0

I created a custom post type named "listas" and a custom taxonomy named "taxolistas".

I would like to fix this function from the plugin Thumbs Rating to make it filter posts by custom taxonomies from Custom Post Types.

Thanks in advance.

if (!function_exists('thumbs_rating_top_func')):
    function thumbs_rating_top_func($atts)
        {
        $return = '';

        // Parameters accepted

        extract(shortcode_atts(array(
            'exclude_posts' => '',
            'type' => 'positive',
            'posts_per_page' => 5,
            'category' => '',
            'show_votes' => 'yes',
            'post_type' => 'any',
            'show_both' => 'no',
            'order' => 'DESC',
            'orderby' => 'meta_value_num'
        ) , $atts));

        // Check wich meta_key the user wants

        if ($type == 'positive')
            {
            $meta_key = '_thumbs_rating_up';
            $other_meta_key = '_thumbs_rating_down';
            $sign = "+";
            $other_sign = "-";
            }
          else
            {
            $meta_key = '_thumbs_rating_down';
            $other_meta_key = '_thumbs_rating_up';
            $sign = "-";
            $other_sign = "+";
            }

        // Build up the args array

        $args = array(
            'post__not_in' => explode(",", $exclude_posts) ,
            'post_type' => $post_type,
            'post_status' => 'publish',
            'cat' => $category,
            'pagination' => false,
            'posts_per_page' => $posts_per_page,
            'cache_results' => true,
            'meta_key' => $meta_key,
            'order' => $order,
            'orderby' => $orderby,
            'ignore_sticky_posts' => true
        );

        // Get the posts

        $thumbs_ratings_top_query = new WP_Query($args);

        // Build the post list

        if ($thumbs_ratings_top_query->have_posts()):
            $return.= '';
            while ($thumbs_ratings_top_query->have_posts())
                {
                $thumbs_ratings_top_query->the_post();
                $return.= '<h2 class="lista-item-h2 lista-item-h2-grade flex">

  <div class="listapop">
   <strong class="lista-ranking "><span class="figlista"></span></strong> </div>    

   <figure class="lista-item-foto">';
                $return.= '<div class="videoPlayer">
    ' . get_the_post_thumbnail($post_id, array(
                    'class' => ' videoPlayer__image lista-item-imagem'
                )) . '
         </div>
   </figure>


   ';
                $return.= ' 
   <div class="votar-lista">

' . thumbs_rating_getlink() . '

   </div>

';
                $return.= '

 <a class="titulo-da-lista modal-link" href="' . get_permalink() . '"> <div class="listItem__data"> <div class="trimtitulo"> ' . wp_trim_words(get_the_title() , 11, null) . ' </div> <span class="listItem__props">
<span class="lista-item-blerg grey default"></span>';
                $return.= '<span class="wikipedia-lista block grey">   ' . mts_excerpt(32) . '  </span></span></div></a>
</h2>';
                if ($show_votes == "yes")
                    {

                    // Get the votes

                    $meta_values = get_post_meta(get_the_ID() , $meta_key);

                    // Add the votes to the HTML

                    $return.= ' (' . $sign;
                    if (sizeof($meta_values) > 0)
                        {
                        $return.= $meta_values[0];
                        }
                      else
                        {
                        $return.= "0";
                        }

                    // Show the other votes if needed

                    if ($show_both == 'yes')
                        {
                        $other_meta_values = get_post_meta(get_the_ID() , $other_meta_key);
                        $return.= " " . $other_sign;
                        if (sizeof($other_meta_values) > 0)
                            {
                            $return.= $other_meta_values[0];
                            }
                          else
                            {
                            $return.= "0";
                            }
                        }

                    $return.= ')';
                    }
                }

            // Reset the post data or the sky will fall

            wp_reset_postdata();
        endif;
        return $return;
        }

    add_shortcode('thumbs_rating_top', 'thumbs_rating_top_func');
endif;

1 Answer 1

0

You would specify listas as the post_type in the Query arguments. And specify taxolistas along with any terms of the taxolistas taxonomy in a tax_query.

$args = array(
    'post_type' => 'listas',
    'tax_query' => array(
        array(
            'taxonomy' => 'taxolistas',
            'field' => 'slug',
            'terms' => array ( 'taxolistas-term1', 'taxolistas-term2' )
        )
    )
);
0

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.