mercredi 22 juin 2016

WP PHP - loop trough custom query - according to number of likes - get tag names - no double names

I am creating a WP menu where post tags are cities. Every post has like counter. I have created custom query trough posts. Post order is descending according to number of likes. Here is the code:

<?php

// The Popular Query
$wp_query = new WP_Query(array(
    'post_type' => array('post'),
    'meta_key'  => 'kodex_post_likes_count',
    'orderby'   => 'meta_value_num',
    'order'     => 'DESC',
        'posts_per_page' => -1 

));

// The Loop
if ( $wp_query->have_posts() ) {

    while ( $wp_query->have_posts() ) {
        $wp_query->the_post();

                //display tags as a list
                echo the_tags( '', '', '' ); 



        }

}

/* Restore original Post Data */
wp_reset_postdata();


?>

This works fine, except I am getting multiple tag (city) name. (As much posts there are with that same tag) I understand the problem but I am not very good with PHP and therefore I am wondering if there is a way to resolve this with PHP.

(I am able to resolve it with javascript but I would rather make it with PHP if it is possible and learn something new by the way.)

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire