Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add new options field to Genesis custom post type archives
Tagged: CPT, CPT settings, Custom fields, Meta box, save_post
- This topic has 7 replies, 3 voices, and was last updated 7 years, 9 months ago by
Aleksandr.
-
AuthorPosts
-
May 8, 2017 at 5:43 am #206090
Aleksandr
MemberI am trying to add a new setting to the archive page for a specific custom post type. I have been able to add metaboxes to the correct archive page, but do not know how to save the settings values.
To add metaboxes to the custom post archive page I used this tutorial:
https://joshuadnelson.com/adding-genesis-cpt-archive-settings-metaboxes/I created a custom field using WordPress' built-in Custom Fields settings, but cannot read that field in the archive. I am guessing that this is because the field needs to be created specifically for the settings page.
Does anyone know how to create a new archive setting?
May 8, 2017 at 5:51 am #206092Victor Font
ModeratorIf you added everything correctly, the saving should be automatic when you save the post. Examine the WordPress post_meta table for the saved values. The archive page won't display a custom field unless you customize the archive template with genesis_get_cpt_option.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 8, 2017 at 6:37 am #206096Aleksandr
MemberHi Victor,
I am still stuck. I definitely don't think that I added everything that's necessary. I only added the metaboxes to the CPT archive, but no saving routine yet. I cannot see the saving routine in the example that I posted and have not found any other references on how to do this.
Are there references on how to add new settings fields to Genesis CPT archive pages?
The genesis_get_cpt_option is what I hope to use in my theme. But, like I said, at this time there is no 'key' for it to get a setting value from and I do not understand how to create this key.
May 8, 2017 at 7:05 am #206107Victor Font
ModeratorAs I said earlier, saving is automatic. There is no saving routine to add. Check the post_meta table.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?May 8, 2017 at 2:44 pm #206131Brad Dalton
ParticipantThere's a few steps he's missed.
I assume you've hooked in the HTML for the input form correctly and now you need to save the data so you can output somewhere. Whats the box for?
You need to use save_post to save the input data.
Genesis also uses its own function for different checks which is called genesis_save_custom_fields.
Once you save the input data correctly, you can then call it anywhere in a custom function with hook or function call in template file.
The only time you don't need to save the data is when using the custom field boxes native to WordPress as these already use save_post.
Note : Genesis has updated the file structure for meta boxes and rewritten the code which now uses new functions so the code you linked to is now outdated.
May 9, 2017 at 1:20 am #206145Aleksandr
MemberHi Brad and Victor,
I have yet to figure this out, so any help is appreciated.
To confirm, I am trying to add a new setting to the Custom Post Type Archive Settings Page.
The setting will be for a eur_in_usd exchange rate that the user will manually set. This eur_in_usd value will be used to convert listing prices from Euros to USD for front-end display. The custom post type is for 'real-estate', and has an additional field for prices. The custom post type and the prices field work fine.
Because the same value for eur_in_usd is relevant for all listings I thought that the best place to add it to is the real-estate archive page settings (genesis-cpt-archive-settings-real-estate).
My confusion is around the way to add this setting. In the example I referenced I do not see any function that saves the output. I am guessing that it is done automatically as part of 'Save Changes' procedure on the Archive settings page. Although I have not been able to find any documentation on this.
I am also unable to see any function that adds this option to the array.
From my assumption, I guessed that the HTML form name determines which setting to update. Please confirm if anything else is necessary to add eur_in_usd to the settings array and to update it.
The current form looks like:
<label for="' . GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX . 'real-estate[eur_in_usd]">1 EUR in USD: </label>
<input type="number" step="0.000001" name="' . GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX . 'real-estate[eur_in_usd]" value=""/>I have used the location of the settings ("' . GENESIS_CPT_ARCHIVE_SETTINGS_FIELD_PREFIX . 'real-estate") to echo currently existing settings with genesis_get_cpt_option (and genesis_get_option). Using phpMyAdmin I am able to see the current options for genesis-cpt-archive-settings-real-estate, and nothing that I have done so far added the eur_in_usd to the array.
May 9, 2017 at 2:38 pm #206207Brad Dalton
ParticipantSaving the data is not done automatically. In your case, the easiest solution is to use a plugin like ACF otherwise you require advanced coding skills.
May 16, 2017 at 5:46 am #206527Aleksandr
MemberA follow up on this post.
I did figure out that the problem was to do with my naming convention for the post type. I called it real-estate. When I renamed the post type as well as anything that mentioned it the settings page started working flawlessly. My guess is that the - in the middle caused some problems.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.