WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query and post__in (5 posts)

  1. cataua
    Member
    Posted 7 months ago #

    Hi, folks!

    I used page_options to define my frontpage posts, and use this code to get que posts for a slide

    $slide_home = get_option('posts_home-slide'); // this retuns a string like this "481,1,922'
    $include = explode(',',$slide_home);
    $argsSlide = array(
    	'post_type'=>'any',
    	'post_status'=>'publish',
    	'posts_per_page'=>'-1',
    	'post__in'=>$include
    	);
    $slide = new WP_Query($argsSlide);
      if ($slide->have_posts()):
        while($slide->have_posts()):
            $slide->the_post();
        endwhile;
       endif;
    wp_reset_query();
    wp_reset_postdata();

    But this query did not return the 3 posts I pass in post__in and return more than three. Someone could help me?

  2. bcmann
    Member
    Posted 7 months ago #

    What do you get when you do a print_r on the $include array? Do you only get the three ID's that you're expecting?

  3. cataua
    Member
    Posted 7 months ago #

    The $include give me a array with the Ids, like this
    Array ( [0] => 418 [1] => 1 [2] => 922 ), and yes the $include array give only the three Id's there I get from the DB.

  4. bcmann
    Member
    Posted 7 months ago #

    Have you tried removing all arguments except 'post__in'? I'm thinking that your 'posts_per_page'=>'-1' is the problem, but I'd try removing 'post_type' too. I'd probably leave 'post_status' to make it easier to manage your posts.

  5. cataua
    Member
    Posted 7 months ago #

    Yes, I already did this and give the same return :/ Funny I made a short code for the next sections and works well the post__in and WP_Query..... :/

Reply

You must log in to post.

About this Topic