Luigi
Luigi

Reputation: 75

How can I show the tags for each post in the result of my query - WP

I have the following query:

$recent_posts = wp_get_recent_posts(array( 
'post_type' => 'post',
'post','numberposts' => 9,
'post_status' => 'publish'

foreach($recent_posts as $post1) { $j++

and print the result in a html table.

echo $post1['post_title'];
echo $post1['post_content'];

but not how to display the tags associated with post

Upvotes: 0

Views: 79

Answers (2)

Luigi
Luigi

Reputation: 75

i can use

the_title();
get_the_content();
the_tags('Tags: ',','); etc

previously declared:

$temp_query = $wp_query; 
            $args = array(
                            'orderby'       => 'post_date',
                            'order'         => 'DESC',
                            'post_type'     => 'post',
                            'numberposts' => 9,
                            'post_status' => 'publish'
                        );

            query_posts( $args );

            if (have_posts()) 
                while ( have_posts() ) : the_post();

Upvotes: 0

Michal Przybylowicz
Michal Przybylowicz

Reputation: 1668

If You know the post_id You can use:

wp_get_post_tags( $post_id, $args )

More here: https://codex.wordpress.org/Function_Reference/wp_get_post_tags

Upvotes: 1

Related Questions