• Resolved berlinwebmaster

    (@berlinwebmaster)


    It seems that the taxonomy operator for the MLA gallery applies to categories OR tags, but not both at the same time.

    For example, if I have the following code to display a list of PDF files:
    [mla_gallery post_mime_type=application/pdf post_parent=all columns=1 link=file size=none mla_markup=ul ?attachment_category=’A’,’B’ attachment_tag=1,2 tax_operator=AND orderby=”title ASC”]

    It will show PDFs that are in Category A AND B (regardless of tag)… as well as PDFs that are tagged 1 AND 2 (regardless of category).

    This means if I have category C but tagged 1 and 2, then it will appear in my list.

    What I really want is category=A and category=B and tag=1 and tag=2. Why do I want this? Consider that I gives my PDFs with a category as well as tags for month and year. If I want to display PDFs of a specific category for June 2013 and another list of the same category for July 2012… this becomes impossible to do.

    I’d like to know if there is a way to make my query match ALL tags and ALL categories both together? Otherwise I have to either switch to 100% categories, or 100% tags, both of which aren’t the most desirable solution.

    Please help!

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your interest and for this great question. You’re right, when a query includes more than one “simple taxonomy query” they are joined by an “OR” relation.

    This is why WordPress invented the “tax_query” and why MLA supports it. The query you want is similar to the “Display posts from several custom taxonomies, using tax_query” example. I think you can get the results you want by replacing the simple taxonomy queries in your [mla_gallery] shortcode with the following tax_query parameter:

    tax_query="array(
    	'relation' => 'AND',
    	array(
    		'taxonomy' => 'attachment_category',
    		'field' => 'slug',
    		'terms' => array( 'A', 'B' ),
    		'operator' => AND'
    	),
    	array(
    		'taxonomy' => 'attachment_tag',
    		'field' => 'slug',
    		'terms' => array( '1', '2' ),
    		'operator' => AND'
    	)
    )"

    I have formatted this example with tabs and line breaks for clarity. You may have to replace the tabs with spaces to get it to work in real life.

    The syntax is cumbersome and must be a valid PHP array specification. It’s a bit painful but also powerful; see the Codex documentation of the WP_Query class for lots of examples.

    I’ll mark this issue resolved for now, but please add to it if you have any problems or further questions. I want to make sure you get the results you need.

    Thread Starter berlinwebmaster

    (@berlinwebmaster)

    Works like a charm. The only modification was to put single quotes around the AND operator:

    tax_query="array(
    	'relation' => 'AND',
    	array(
    		'taxonomy' => 'attachment_category',
    		'field' => 'slug',
    		'terms' => array( 'A', 'B' ),
    		'operator' => 'AND'
    	),
    	array(
    		'taxonomy' => 'attachment_tag',
    		'field' => 'slug',
    		'terms' => array( '1', '2' ),
    		'operator' => 'AND'
    	)
    )"
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘TAX_OPERATOR=AND’ is closed to new replies.