[Support request] change query for single if post has category

Home Forums Support [Support request] change query for single if post has category

Home Forums Support change query for single if post has category

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2328190
    Tesco

    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

    #2328254
    David
    Staff
    Customer Support

    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:

    https://wordpress.stackexchange.com/a/169862

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.