WordPress.org

Ready to get started?Download WordPress

Forums

How to display mutliple posts by ID (5 posts)

  1. pherank
    Member
    Posted 2 years ago #

    I would love to know why the results from this query only displays a single post, even though each ID is valid, and using either of the single IDs will display the appropriate post for that ID.

    <?php /* Remove category 5 from Home and Archive page displays */ ?>
    <?php
    	if ( is_home() || is_archive() ) {
    	global $query_string;
    	query_posts($query_string . '&cat=-5&p=273,225');
    	}
    ?>
  2. NateJacobs
    Member
    Posted 2 years ago #

    Try

    global $wp_query;
    $args = array_merge(
    	$wp_query->query,
    	array(
    		'post__in' => array( 273, 225 ),
    		'cat' => '-5'
    	)
    );
    query_posts( $args );
  3. pherank
    Member
    Posted 2 years ago #

    Thanks Nate: that does work. But now I'm realizing that I needed to use the query string syntax so that I could override a WP plugin (w/ aspo=vanilla):

    query_posts($query_string . '&cat=-5&p=273,225&aspo=vanilla');

    But for whatever reason only the first ID number is displayed. Arrrgh.

  4. Big Bagel
    Member
    Posted 2 years ago #

    This won't work?

    global $wp_query;
    $args = array_merge(
        $wp_query->query,
        array(
            'post__in' => array( 273, 225 ),
            'cat' => '-5',
            'aspo' => 'vanilla'
        )
    );
    query_posts( $args );

    The p argument can only take a single ID.

    http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

  5. pherank
    Member
    Posted 2 years ago #

    Thanks, that explains it. It would have to be handled as an array.

Topic Closed

This topic has been closed to new replies.

About this Topic