Archived topic
Apply post setting to my custom post type
6 replies · Started by Silvio on December 1, 2021
Hi, and sorry for my English
How do I get the option_generate_blog_settings from the posts, to apply them to my custom post type.
Hi Silvio,
This is the filter you are looking for:
https://docs.generatepress.com/article/option_generate_blog_settings/#examples
Here is the conditional tag:
https://codex.wordpress.org/Conditional_Tags#A_Post_Type_Archive
For more examples:
https://generatepress.com/forums/search/option_generate_blog_settings/
Thank you very much for the answer, but what I can not achieve is how I get the options that are in the customizer.
what I would like to do is something like
add_filter( 'lh_custom_search_results_page_settings', 'option_generate_blog_settings');
function lh_custom_search_results_page_settings( $options ) {
if ( get_post_type( get_the_ID() ) == 'efg_help' ) {
$settings = wp_parse_args(
get_option( 'generate_blog_settings', array() ),
generate_blog_get_defaults()
);
return $settings;
}
return $options;
That is, the same options that the posts have, they also affect my custom post type
Hi Silvio,
Can you explain a bit more on what you're trying to do?
The code you've shared has issues by the way.
This line:
add_filter( ‘lh_custom_search_results_page_settings’, ‘option_generate_blog_settings’);
Should be:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings');
As for the function you've shared:
It will apply the default blog settings on custom post type efg_help. But if you're aiming for its archive page, you should use is_post_type_archive() https://developer.wordpress.org/reference/functions/is_post_type_archive/ on the condition.
Hi Silvio,
I think you only need these 3 snippets to activate these options for your CPT, so that the CPT can pull the options from customizer > blog :
add_filter( 'generate_blog_columns', function( $columns ) {
if ( is_post_type_archive('my-post-type') ) {
return true;
}
return $columsn;
} );
add_filter( 'generate_entry_meta_post_types', function( $types ) {
$types[] = 'my-post-type';
return $types;
} );
add_filter( 'generate_footer_meta_post_types', function( $types ) {
$types[] = 'my-post-type';
return $types;
} );
Can you give it a try and let me know?
Thank you very much Ying, I will go that way
You are welcome :)