Problem with type plugin and custom taxonomies

Function

function get_taxonomy_names($post_id, $term_name) {
$collections = wp_get_post_terms($post_id, $term_name, array("fields" = "all"));
$count       = count($collections);
$return = '';
if($count  0) {
    $i = 1;
    foreach($collections as $collection) {
        $return .= $collection-name;
        if($count  1) {
            if($count == $i) {
                continue;
            }
            $return .= ', ';
        }
        $i++;
    }
}
return $return;

}

Product template

 $products_category = get_categories(array('taxonomy'='category-products'));?


    div class="sorting-block"
        div class="content-xs"
            ul class="sorting-nav sorting-nav-v1 text-center"
            ? foreach ( $products_category as $collection ): ?
                li class="filter" data-filter="category"?=$collection-name;?/li
            ?endforeach;?    
            /ul
        /div


    ? $products = get_posts( array('post_type' = 'products', 'posts_per_page' = 400,) ); ?

    ? foreach ( $products as $post ) : setup_postdata( $post ); ? 
    ? $pic               = types_render_field("product-pic", array("url"="true")); ?
    ? $serial_number     = types_render_field("serial-number", array("url"="true")); ? 

        ul class="row sorting-grid"
            li class="col-md-3 col-sm-6 col-xs-12 mix" data-cat="category"
                a href="#"
                    img class="img-responsive" src="?=$pic;?" alt=""
                    span class="sorting-cover"
                        span? the_title(); ?/span
                        p/p
                    /span
                /a
            /li     
        /ul
    ?endforeach;?

Problem

I have product category which I did by types plugin 'custom taxonomies'. I want to show products by category when somebody clicks the category name that should show just that products which registered to for example "acril" category. Problem is when I am debugging products it is not showing category. So I should connect both foreach circle if you paid attention I have data-filter in circle 1 and data-cat in the second circle with value 'category'. that should be dynamic and what can be key for that connection if post not showing the any keys.

Topic plugin-types custom-taxonomy custom-post-types Wordpress

Category Web


You need to pass the category name as well if you want to show posts from specific category..

You just need to add one more param to the get_posts array.

REPLACE THIS

<? $products = get_posts( array('post_type' => 'products', 'posts_per_page' => 400,) ); ?>

WIth THIS

<? $products = get_posts( array('post_type' => 'products',  'category_name' => 'category_name_here', 'posts_per_page' => 400,) ); ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.