WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query and post__in (4 posts)

  1. caddoo
    Member
    Posted 3 years ago #

    I'm using WP_Query to generate a custom search results page that displays posts under custom taxonomy terms.

    The thing with this is, I want to be able to have duplicate posts in the search results as one post might be assigned multiple terms.

    What i currently have is the order of the posts i want in a single dimensional array:

    eg: array ( 1, 2, 3, 1, 2, 3, 1, 2, 3 )

    (ill be able to determine the terms for each myself and generate the headers accordingly)

    The issue is when I pass this array to post__in it will only display the posts once.

    Is there anyway around this without modifying the WP Core.

    Thanks,

    Matt

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    loop through your array and use get_post() or a query for each individual id?

  3. caddoo
    Member
    Posted 3 years ago #

    The reason i'm using WP_Query is so i can use the inbuilt pagination.

    Doing it without the WP loop will prevent this if im right?

  4. caddoo
    Member
    Posted 3 years ago #

    Looking into query.php

    I can see wordpress uses the MySQL syntax 'IN' and MySQL will never return the same row twice.

    } elseif ( $q['post__in'] ) {
    			$post__in = implode(',', array_map( 'absint', $q['post__in'] ));
    			$where .= " AND {$wpdb->posts}.ID IN ($post__in)";

    Ill have to write my own option i think and hook it into WP_Query

Topic Closed

This topic has been closed to new replies.

About this Topic