• Resolved nakuable

    (@nakuable)


    Dear Friends,

    I am developing a new element in my company website but I need your help.

    My question is how I can verify if a term of attribute have products.

    The idea is:
    $anat_representada_producto = wp_title(”,false,RIGHT);
    if the term with name in the variable $anat_representada_producto have products then
    echo do_shortcode(“[products attribute=’Marca’ terms=’$anat_representada_producto’ limit=’4′ orderby=’date’]”);
    if not have products then don’t show nothing.

    I hope I explained this well.

    Thank you very much for your help.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nakuable

    (@nakuable)

    Hello, I really need help.

    Can you help me?

    Thank you very much.

    Hello @nakuable,

    I’m sorry no one spoke up on your post before now. I’m not sure if you still need help here. In case you do, one way you could approach this is to set up a query using wp_query() to pull all products that have that attribute. Here’s an example of how that could look:

    
    $products = new WP_Query( array(
       'post_type'      => array('product'),
       'posts_per_page' => -1,
       'tax_query'      => array( array(
            'taxonomy'        => 'pa_color',
            'field'           => 'slug',
            'terms'           =>  array('blue', 'red', 'yellow'),
            'operator'        => 'IN',
        ) )
    ) );
    
    // The Loop
    if ( $products->have_posts() ): while ( $products->have_posts() ):
        
    	// output content based on products having that attribute
    	
    endwhile; else :
    	
    	// output content if there are no products with that attribute.
    	
    endif;
    

    I hope that points you in a possible direction. Let me know if you have any questions.

    Best.

    Plugin Support EtienneP a11n

    (@etiennep)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘count qty of products with a term’ is closed to new replies.