Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to do a small modification on WP site done by someone else. And my WP experience is close to zero. But I'm comfortable with PHP.

Wordpress Version: 3.8

Plugins:

ONLY Advanced Custom Fields 4.3.4 [ACF] http://wordpress.org/plugins/advanced-custom-fields/

There's only one group Products made with ACF with fields like title, description, price, store. Site owner add Products with details & which stores they are available at.

currently the products are displayed correctly based on the url

http://mysite.site/store1

will take to a list of product categories. When user clicks any of the category it will show the filtered products list with the ACF field store

The Problem

All categories are displayed regardless of whether it contain products for the specific stores

ie., category 2 has only one product product 10 and it is only available in store1. But store2 & store3 shows category 2 even though it doesn't have any valid product.

Currently the following code is used to display categories.

$args = array(
    'type'                     => 'post',
    'child_of'                 => 0,
    'parent'                   => '0',
    'orderby'                  => 'name',
    'order'                    => 'ASC',
    'hide_empty'               => 1,
    'hierarchical'             => 1,
    'taxonomy'                 => 'category',
);
$top_categories = get_categories($args);

I want $top_categories to return only those categories with products for current store

Thank you

share|improve this question
1  
What have you tried so far? –  Pat J Jan 20 at 23:52
    
I don't seem to reach anywhere. I tried WP_Query(), get_terms(), get_categories. As said at first I can handle PHP but I don't know how WP internally works. –  Vemman Jan 21 at 10:51
    
OK Thought this will help someone. I used the site generatewp.com to craft my queries. Then implemented those in my custom frontend outside wordpress. The client wanted to display data from WP into another app. –  Vemman Jan 25 at 10:46
    
So is this fixed, or? –  Matias Vad Mar 1 at 8:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.