• Resolved jamesbrodie

    (@jamesbrodie)


    Hi

    I’m using a post-grid block to display content of a particular type. I’m really happy with it but have hit an issue.

    I want to display the 6 latest posts in the category ‘news’. This works fine.

    But then I want to include a particular post of importance, so I add its post id into the ‘include post’ field. What I expect to happen is it then forces that post to be included whether it’s one of the latest 6 or not, and the other 5 are the latest 5 posts.

    What actually happens is that it displays ONLY that one post and nothing else.

    Is this the intended behaviour? It doesn’t make sense to me.

    Regards
    James

Viewing 1 replies (of 1 total)
  • Plugin Author WPXPO

    (@wpxpo)

    Hello @jamesbrodie,

    WP_Query has ‘post__in’ and ‘tax_query’ parameters. When you choose any Taxonomy and Include it at the same time then WP_Query intercepts the common post. You can read the wp_query documentation https://developer.www.ads-software.com/reference/classes/wp_query/.

    Here is the example-

        $args = array(
            'post_type' => 'post',
            'posts_per_page' => 6,
            'orderby' => 'post__in',
            'order' => 'desc',
            'paged' => 1,
            'post_status' => 'publish',
            'post__in' => array(3896, 3893),
            'ignore_sticky_posts' => 1,
            'tax_query' => array(
                'relation' => 'OR',
                0 => array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => array('fashion', 'entertainment')
                )
            ),
        );
        $query = new WP_Query( $args );

    It’s possible to append post__in to the query. But currently, our plugins have no option like this.
    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘‘Include Post’ behaves unexpectedly’ is closed to new replies.