Archived topic
Category entries
8 replies · Started by Catalin on April 28, 2018
Hi,
I add info on my blog via pods.io plugin for custom posts and I'm using wordpress categories to group my entries. However, when I click on a category name, I get a Nothing found page and the search bar.
Any idea how could I display this entries?
Thanks.
I already tried to add to functions.php the following codes:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','review');
$query->set('post_type',$post_type);
return $query;
}
}
and
add_action( 'pre_get_posts', function ( $q )
{
if ( !is_admin() // Only target front end queries
&& $q->is_main_query() // Only target the main query
&& $q->is_category() // Only target category archives
) {
$q->set( 'post_type', ['post', 'review'] ); // Adjust as needed
}
});
It didn't work.
Hmm, that's strange.
What are your permalinks set to in "Settings > Permalinks"?
Can you deactivate your custom functions, then re-save the permalink settings?
I forgot to change the permalinks and it was set to Date and time. Now it's set to Post name.
What do you mean by Custom functions?
Meanwhile I found a solution via a very old plugin: Custom posts type archive (https://wordpress.org/plugins/custom-post-type-taxonomy-archives/), like 7 years old. It did the trick. :)
The custom functions you pasted in your reply above.
Something must be interfering with the permalinks, as /category/name is a typical WP permalink structure. Perhaps try deactivating your other plugins/custom functions and then re-add them one by one to see if it's a plugin issue.
I deactivated all the plugins, reactivated one by one, and nothing happen. I'm pretty happy that it works, now I can sleep at night. :) If this is something that you'll like to check for you, I have no problem sending you the pass to check some things.
It's all working as it should now?
Yes. Everything's perfect.
Awesome :)