0

I've been working on my frontpage for a website, and now, at the bottom I want to add another post, outside the main loop, to this page.

I've used a WP_Query:

$args = array( 
        'post_type'   => 'post',
        'tag_id'      => '32'
    );


    $fp_post = new WP_Query( $args );

    if($fp_post->have_posts()) :
        while ($fp_post->have_posts()) : $fp_post->the_post();
            the_content();
        endwhile;
    else:
        echo 'its not working';
    endif;

Now, I get back that it's not working, but I'm sure there is a post with an id of 32. This should mean my array is empty, but I don't know why this is. Did I make some basic mistake somewhere?

1 Answer 1

1

If you're trying to get a post with the id of 32, the parameter you would use is p, which is one of the Post & Page Parameters. tag_id is used for querying posts with a particular Tag ID.

$args = array( 
        'post_type' => 'post',
        'p'         => 32
);

$fp_post = new WP_Query( $args );

if ( $fp_post->have_posts() ) :
    while ( $fp_post->have_posts() ) : $fp_post->the_post();
        the_content();
    endwhile;
else:
        echo 'it is not working';
endif;
1
  • You got it, Rik! Commented Nov 30, 2016 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.