Forums

wp_query() specific posts with post__in (5 posts)

  1. romenov
    Member
    Posted 2 years ago #

    Hello,

    I'm trying to get a specific amount of pages using post__in, I've tried it several ways but it always give a blank result. What am I doing wrong?

    $bloblor =  array(43,45);
    		$args = array(
    		'post__in' => $bloblor);
    		$spotlight = new WP_Query($args); while ($spotlight->have_posts()) : $spotlight->the_post(); $do_not_duplicate = $post->ID; ?>
    			 <?php the_content(); ?>
    		<?php endwhile; ?>
  2. Michael Fields
    Member
    Posted 2 years ago #

    do this before your normal loop:

    $include = array( 37, 1 );
    query_posts( array( 'post__in'=>$include ) );
  3. romenov
    Member
    Posted 2 years ago #

    Thanks,

    This doesn't work for pages though, is there a way that I can make this work for pages?

  4. Michael Fields
    Member
    Posted 2 years ago #

    Not as far as I know. If needed ths content, I would use a custom query like this:

    $spotlight = $wpdb->get_results( "SELECT post_content FROM $wpdb->posts WHERE ID IN( 31,41 )" );
    if ( $spotlight ) {
    	foreach( $spotlight as $spot ) {
    		print apply_filters( 'the_content', $spot->post_content );
    	}
    }

    Note, you will want to keep the query as simple as possible to try to ensure that there are no problems when you upgrade. he query above will pose little problems do to the act that it references on the "post_content" column of the "post" table -> both of which have been a part of WordPress for a long time.

    Best of luck,
    -Mike

  5. prw
    Member
    Posted 2 years ago #

    dont forget to add 'post_type'

    so you would have:

    $bloblor =  array(43,45);
    $args = array(
    'post_type' => 'page',
    'post__in' => $bloblor);
    $spotlight = new WP_Query($args); while ($spotlight->have_posts()) : $spotlight->the_post(); $do_not_duplicate = $post->ID; ?>
    <?php the_content(); ?>
    <?php endwhile; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags