• Resolved laikmosh

    (@laikmosh)


    hellos everybody, great plugin, i can do anything with my website without knowing php, thanks Eliot!.
    so, im trying to loop for posts that have 2 categories, in the reference file i found that i could use compare=”and” and i tried this code:

    [loop category=”Presentaciones, br events” orderby=”date” order=”DESC”]
    [content]
    [/loop]

    but this way it displays all posts from both categories, i also tried tihs code:

    [loop category=”Presentaciones” orderby=”date” order=”DESC”]
    [if category=”br events”]
    [content]
    [/if]
    [/loop]

    but this one displays no posts at all…

    i need this code to display posts only if they have both categories: “Presentaciones” AND “br events”, is there any way i can achieve this? what am i doing wrong?

    thanks!

    https://wordpress.org/plugins/custom-content-shortcode/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I think the issue may be with the category “br events”. Are you sure it’s supposed to have a space in the category slug? You can check under Dashboard -> Content for the exact slug.

    Other than that..this should get posts with both categories:

    [loop type="post" category="category_1, category_2" compare="and"]

    I hope that helps!

    Thread Starter laikmosh

    (@laikmosh)

    Thanks, I didn’t know it was using the category slug, i always thought it was the category name, but it tried it with the correct category name and it still didn’t work.
    this is the exact code im using for the loop:

    [loop category=”Presentaciones, br-events” orderby=”field” key=”_cs-expire-date” order=”DESC” compare=”and”]

    it is displaying all the posts, but now that i know it uses the category slug, this code worked fine:

    [loop category=”Presentaciones” orderby=”field” key=”_cs-expire-date” order=”DESC”]
    [if category=”br-events”]

    i think your suggestion should have worked, am i putting the “compare=”and”” in the right position?

    Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I looked into the code, and realized this area (query by multiple categories) needs some improvement. The compare parameter is not being checked, but this syntax works:

    [loop category="category_1+category_2"]

    Instead of a comma “,” there’s a plus symbol “+” between the categories. This is a feature in WP_Query.

    Thanks for pointing this out. I’ll try to improve this so compare=”and” will work the same way.

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, in the latest update, I made sure that compare=”and” will work for multiple categories or tags:

    [loop category="category_1,category_2" compare="and"]
    Thread Starter laikmosh

    (@laikmosh)

    Nice, THANKS!; wow, what a plugin support, congrats!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Loop if post has both categories’ is closed to new replies.