php - WP_Query->post_name returns null -
i'm trying post_name attribute wp_query($args)
function in wordpress. if i'm using var_dump($wp_query);
shows me post_name
attribute not empty or null. title of post.
but if i'm trying echo using echo $wp_query->post_name;
returns empty string.
this how define $wp_query
:
$args = array('posts_per_page' => 5, 'tag' => 'general'); $wp_query = new wp_query( $args );
there posts has tag "general" cannot reason.
can please explain behaviour or tell me i'm doing wrong?
this because $wp_query
isn't single post, posts match query args. means have loop on posts in query result in way. instance, can this:
$args = array('posts_per_page' => 5, 'tag' => 'general'); $wp_query = new wp_query( $args ); // posts query $posts = $wp_query->get_posts(); // loop through posts foreach( $posts $post ) { echo $post->post_name; }