I need to query for a post outside of another post: I am using a hook to import a page builder template and I need a query in relationship to the post it is hooked into. I not a huge fan of builders but they are popular.

I am using this code:

<?php 

$mypost = array( 'post_type' => 'post' );
$loop = new WP_Query( $mypost );


if ($loop->have_posts()) : while ($loop->have_posts())  : ($loop-      >the_post());

get_the_ID();  
//the_ID();
//the_title();

endwhile; 
endif;
wp_reset_query();

and it works to a degree but returns all post not singular post data

That’s it in a nutshell. query data from the post it’s hooked into not from the post that the template was created with. It will return the id and title if I comment them back in but it does it for all posts on my dev box of type ‘post’

Brad

1 Answer
1

Retrieve the post’s ID from the $post object.
$post->ID;

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *