• I am querying the database for custom meta tag information using the query below. I understand how to take that query and use a custom loop to display the data, but what I want to do is take the query results and stuff it into the standard WordPress data set for use in the standard loop, as I wish to maintain pagination capability.

    I am pulling my hair out and cannot figure out how to stuff these results into the standard loop. Any help most appreciated. Thanks in advance.

    $querydetails = "
    SELECT wposts.*
      FROM $wpdb->posts wposts
    INNER
      JOIN ( SELECT post_id
               FROM $wpdb->postmeta wpostmeta
              WHERE ( ( wpostmeta.meta_key = 'available'
                    AND wpostmeta.meta_value =  '$available' )
                   OR ( wpostmeta.meta_key = 'beds'
                    AND wpostmeta.meta_value $operator_beds '$beds' )
                   OR ( wpostmeta.meta_key = 'baths'
                    AND wpostmeta.meta_value = '$baths' )
                   OR ( wpostmeta.meta_key = 'type'
                    AND wpostmeta.meta_value = '$type' )
                   )
             GROUP
                 BY post_id
             HAVING COUNT(*) = 4 ) AS t
        ON t.post_id = wposts.ID
     WHERE wposts.post_status = 'publish'
       AND wposts.post_type = 'post'
    ORDER
        BY wposts.post_date DESC
     ";
Viewing 1 replies (of 1 total)
  • Consider just returning the post ID as your results, into an array, then use that with post__in argument to modify your query.

    coffee2code also created a plugin called Inject Query Posts that might have some use for you…

Viewing 1 replies (of 1 total)
  • The topic ‘How to stuff custom query results into "The Loop"’ is closed to new replies.