How can I get the first post from a WP_Query result?
$connected = new WP_Query( array(
// Arguments
));
// This doesn't work..
echo $connected[0]->post_name;
How can I get the first post from a WP_Query result?
$connected = new WP_Query( array(
// Arguments
));
// This doesn't work..
echo $connected[0]->post_name;
You must be logged in to post a comment.
If you poke through
WP_Query
the set of queried posts is saved intoposts
property and current post gets assigned topost
one (each time loop iterates).So you could do
$connected->posts[0]
if you need to just fetch that, but it might be more convenient to do$connected->the_post();
then$connected->post
if you need to skip first one and process the rest in normal loop.You may use a code like this: