Support » Plugin: Pods - Custom Content Types and Fields » Multiple reference in template

  • Resolved coadr93

    (@coadr93)


    Hi. I am trying to achieve the following.

    List all taxonomy terms from a custom taxonomy.

    Exclude 1 particular term.

    In the same query, list all posts from the excluded taxonomy term and mix them with the other taxonomy terms.

    For context, i have cities (tax) and locations (post type). The cities with multiple locations are taxonomies, but the single locations are posts only (thus they become cities in a way).

    I’ve tried it in templates… But I can only reference either the post type or the taxonomy.

    I was thinking something like setting two tenplates with <.li.>, wrapping both in <.ul.> then order them alphabetically via JS… But it doesn’t seem very elegant.

    Can you help? I can find nothing on the web regarding a WP query that mixes tax terms with posts.

    Thanks

    • This topic was modified 1 month ago by coadr93.
    • This topic was modified 1 month ago by coadr93.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter coadr93

    (@coadr93)

    Ok, here’s how I achieved it… but it’s not elegant at all πŸ™

    <ul id="stocksymbols">
    
    [pods name="taxonomy_name_cities"]
    
    [if include_in_tax_query_custom_field]
    
     	<li>{@name}</li>
    
    [/if]
    
    [/pods]
    
    [pods name="post_type_name_location"]
    
    [if single_in_city_custom_field]
    
     	<li>{@name}</li>
    
    [/if]
    
    [/pods]
    </ul>

    Then I used JS I found online to reorder the items Alphabetically, since they are all in the same UL.

    <script>
    
    function sortList(ul) {
      var ul = document.getElementById(ul);
    
      Array.from(ul.getElementsByTagName("LI"))
        .sort((a, b) => a.textContent.localeCompare(b.textContent))
        .forEach(li => ul.appendChild(li));
    }
    
    sortList("stocksymbols");
    
    </script>

    So basically…

    1. I am querying the taxonomy terms and posts separately then merging them and reordering them via JS.
    2. To exclude one taxonomy I am using a Y/N custom field on taxonomies. This is also not elegant since I have to set all the terms I want to include to Y and the term I want to exclude to N.
    3. To include only the posts inside the excluded taxonomy I am using another Y/N custom field.

    I certainly hope there is a better solution to this…

    So what I’m looking to achieve is Exclusion Rules (for the taxonomies) and Inclusion Rules based on taxonomy for posts…

    I can live with sorting the <.li.> elements via JS.

    Thank you and I hope you have some ideas.

    • This reply was modified 1 month ago by coadr93.
    • This reply was modified 1 month ago by coadr93.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @coadr93

    Personally I would advice you to go the PHP route for this one. You can combine the results of your queries and reorder properly before running your loop.
    Pods templates aren’t meant for sunning complex queries, PHP is way more flexible.

    Cheers, Jory

    Thread Starter coadr93

    (@coadr93)

    Hey, Jory! Thanks for your reply.

    Can you link me to any documentation that might be helpful for PHP pods template?

    I’ve been browsing the pods.io website but mostly 404s or pages that have no content…

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Sorry about the 404s, I’m working as quickly as possible to resolve the issue this week and get everything back up.

    Thread Starter coadr93

    (@coadr93)

    Hey, Scott. Thanks! πŸ™‚ You guys are doing a great job! I hope I will be able to help at some point with the documentation but I’m still learning Pods myself.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Just following up, this past weekend we spent days working on this and most of those 404s should be resolved.

    We are not going to bring over the pods_api() docs because we will instead spend that time working on the new Code Reference site that is phpdoc powered. There’s too many methods to bring over and the process was very time intensive.

    Thread Starter coadr93

    (@coadr93)

    Thanks for the update and for your work, Scott!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.