• Resolved ryleef

    (@ryleef)


    I am currently having problems trying to display only files of multiple category types. I am using the Enhanced Media Library plugin which sets files taxonomy as a media_category. Below is the code I am having problems with:

    [dg descriptions=true fancy=true media_category=form media_category=contractor relation=AND id=-1]

    The above code displays ALL files that have media_category of contractor regardless whether they also have the form media_category as well. I have also noticed that swapping them around (contractor in the first media_category, form in the second) shows all forms regardless if they have a media_category of contractor.

    Any help would be appreciated.

    Cheers

    https://wordpress.org/plugins/document-gallery/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ryleef

    (@ryleef)

    NOTE: I have also tested this with comma separated values:

    [dg descriptions=true fancy=true media_category=form,contractor relation=AND id=-1]

    This doesnt work and displays all files.

    I have also tested with quotes surrounding values (media_category="form")

    Thread Starter ryleef

    (@ryleef)

    From a quick debug, it seems like it ignores the first value (form in this case) and only applies the second (contractor)

    Thread Starter ryleef

    (@ryleef)

    Was able to “fix” this with the addition to the following code in class-gallery.php

    ***NEW***

    foreach ($this->taxa as $taxon => $terms) {
                $terms = $this->getTermIdsByNames($taxon, explode(',', $terms));
                foreach($terms as $term){
                    $taxa[] = array(
                          'taxonomy' => $taxon,
                          'field'    => 'id',
                          'terms'    => $term,
                          'operator' => isset($operator[$taxon]) ? $operator[$taxon] : 'IN'
                    );
                }
    
             }

    ***OLD***

    foreach ($this->taxa as $taxon => $terms) {
                $terms = $this->getTermIdsByNames($taxon, explode(',', $terms));
                    $taxa[] = array(
                          'taxonomy' => $taxon,
                          'field'    => 'id',
                          'terms'    => $terms,
                          'operator' => isset($operator[$taxon]) ? $operator[$taxon] : 'IN'
                    );
    
             }

    Created a separate array for each term so that the ‘AND’ relation worked as expected.

    If there is a “proper” way around this please comment below.

    Plugin Author Dan Rossiter

    (@danrossiter)

    Hi ryleef,

    Please take a look at the NOTE following the relation option documentation on the installation tab.

    I believe you’re looking for “media_category_relation”.

    -Dan

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple Categories with 'AND' relation’ is closed to new replies.