2

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

6
  • Sorry, I am not quite following what you want to do. Do you know what the post id is that you want? If you so you can use get_post( $id ). Commented Feb 17, 2017 at 14:28
  • Hi brad, and welcome to WPSE. Honestly i didn't understand your question at all. Please try and make it more clear, possibly with answers. And prevent unnecessary explanation.
    – Johansson
    Commented Feb 17, 2017 at 14:50
  • OK. I am using a query:
    – Midi Hipi
    Commented Feb 17, 2017 at 15:07
  • 1
    Let me get my thoughts together on this one......
    – Midi Hipi
    Commented Feb 17, 2017 at 15:07
  • The process of narrowing your problem down to a single, answerable question is often enough of an exercise that I answer my own question before answering it. Focus on a very specific item and you'll have a much better chance of getting good, useful answers.
    – jdm2112
    Commented Feb 17, 2017 at 17:50

1 Answer 1

0

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

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.