Archived topic
change query for single if post has category
1 reply · Started by Tesco on August 30, 2022
How can I change the query for single post if that post has a specific category?
These are the args that I need:
$postIds = get_post_meta($post->ID, 'posts_ids', true);
$arrayIds = explode(',', $postIds);
$args = array('post_type' => 'post','post__in' => $arrayIds, 'ignore_sticky_posts' => 1);
Then the template should call something like this:
<?php if(have_posts()): while(have_posts()): the_post(); ?>
So that I can build my custom HTML here
Hi there,
there are many ways to do it.
But the WordPress codex can be your biggest friend. For example this hook:
https://developer.wordpress.org/reference/hooks/type_template/
You can use that for the single_template to select a different template based on whatever conditions you want.
There are examples in the comments of that codex page.
Or theres a specific example here: