• Resolved aeamarkg

    (@aeamarkg)


    Hi. I have a custom taxonomy created called “State Taxonomy.” I am trying to pass it as a usable variable to the loop, and then grab other posts (of CPT “City”) that have a matching State Taxonomy. Code below nets no results.

    
    [pass taxonomy=state_taxonomy]
    [loop type=city taxonomy=state_taxonomy term={TERM} count=12 orderby=rand]
    [field title-link]
    [/loop]
    [/pass]
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • What happens if you use [pass taxonomy_loop=state_taxonomy] instead of [pass taxonomy=state_taxonomy]?

    Try:

    [for each=state_taxonomy]
    [loop type=city taxonomy=state_taxonomy term={TERM} count=12 orderby=rand]
    [field title-link]
    [/loop]
    [/for]

    or

    [for each=state_taxonomy]
    [loop type=city count=12 orderby=rand]
    [field title-link]
    [/loop]
    [/for]
    • This reply was modified 3 years, 3 months ago by polarracing.
    Thread Starter aeamarkg

    (@aeamarkg)

    Thanks, everyone. These 2 actually create the same issue, but in 2 different ways. I have 13 possible “states” as the State_Taxonomy. So, in each solution, it’s looping through all 13 and giving me 12 results for each, or a total of 166.

    My CPT “city” only has 1 state_taxonomy per entry. So, the desired result is to pass its state_taxonomy to the loop and grab 12 random results that have a matching state_taxonomy.

    As an addendum: my original code grabs only 12 results, but those results do not match the state_taxonomy of the CPT City.

    • This reply was modified 3 years, 3 months ago by aeamarkg.

    Then try this:

    [for each=state_taxonomy current=true]
    [loop type=city count=12 orderby=rand]
    [field title-link]
    [/loop]
    [/for]
    Thread Starter aeamarkg

    (@aeamarkg)

    Boom! That did it. Many many thanks. Knowing that setting will be a huge help in the future.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pass Taxonomy as Variable?’ is closed to new replies.