I am wanting to dispaly custom post types on my archive pages using code from here:
but this now gives WP error message of:
Warning: Invalid argument supplied for foreach() in /wp-includes/class-wp-post-type.php on line 613
add_action('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if($query->is_main_query()
&& ( is_category() || is_tag() )) {
$query->set( 'post_type', array('post','cpt') );
}
}
Please let me know what changes are needed to not return errors.
I am wanting to dispaly custom post types on my archive pages using code from here:
https://wordpress.stackexchange/questions/179023/adding-custom-post-types-to-archive-php
but this now gives WP error message of:
Warning: Invalid argument supplied for foreach() in /wp-includes/class-wp-post-type.php on line 613
add_action('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if($query->is_main_query()
&& ( is_category() || is_tag() )) {
$query->set( 'post_type', array('post','cpt') );
}
}
Please let me know what changes are needed to not return errors.
Share Improve this question edited Mar 25, 2020 at 2:45 WordPress Speed 2,2833 gold badges19 silver badges34 bronze badges asked Jan 4, 2020 at 15:54 Timothy BurginTimothy Burgin 132 bronze badges 3 |1 Answer
Reset to default 0The problem could be related to how you register the custom post type.
Did you add the "taxonomies" argument in the register_post_type? If yes, is it a string? Try to convert it in an array of strings.
See the the example below...
register_post_type(
'custom_post_type_slug',
array(
'labels' => array ( /* ... */ ),
'public' => true,
/* ... */
'taxonomies' => array( 'custom_post_taxonomy_slug' ),
)
);
has_archive
is true when registering the post type you will get an archive automatically at/asana/
– Jacob Peattie Commented Jan 6, 2020 at 0:57