• Resolved Alex R

    (@apollolux)


    Hello! For the most part, Pods does what I need it to do and so far without needing to resort to PHP for it. To that end, I’ve come up against what to me appears to be a simple problem.

    I have a custom post type pod, Promo Item, and a custom taxonomy for it, Placement. Placement is hierarchical for convenience, essentially a general collection parent with more specific children locations (e.g. Featured -> Left, Featured -> Bottom, Search Results -> Top, etc). In my pods shortcode for a given page I have in the where placement.term_id=22 OR placement.parent=22 (22 being the term_id of the given collection parent like Featured) to get the Promo Items assigned to that taxonomy or its direct children. This works but uses a hardcoded term_id of the parent taxonomy in question and only handles first-level children. For simplicity I’m only worrying about first-level children, but in the future I may need to consider multi-level.

    I know it’s certainly possible in PHP to pods->find the specific taxonomy by name or slug and get its term_id, then later use that term_id in the subsequent find for the specific Promo Items of that taxonomy or its children, basically call pods->find twice. Is it possible to simulate a subselect in the where of a pods shortcode call? Something like [ pods where="placement.parent=(SELECT term_id FROM placement WHERE slug='featured')" ][ /pods ] ?

    • This topic was modified 3 years, 11 months ago by Alex R. Reason: Formatting
    • This topic was modified 3 years, 11 months ago by Alex R. Reason: Typo
    • This topic was modified 3 years, 11 months ago by Alex R. Reason: Fix 'where'
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @apollolux

    For subqueries you’ll have to write your own queries and need to get familiar with SQL and the WP database. For example placement isn’t an existing table.
    However, I wouldn’t advice doing this in Pods shortcodes as the parser probably won’t interpret the subquery correctly.

    Honestly, you are stretching the limits of what should be done through shortcodes. If you need more complex filtering I would suggest going the PHP route.
    Through PHP you can first get the taxonomies you need and then create the query by the term ID’s you’ve fetched. This is something you cannot do in shortcodes.

    Cheers, Jory

    Thread Starter Alex R

    (@apollolux)

    Hello! Thanks for taking the time to reply.

    For clarification, I understand placement isn’t an existing table, it’s the slug for the custom taxonomy in the OP. I was hoping that I could subquery in the shortcode at least for the parent’s info, but if you’re saying that it’s either unpredictable/unstable results or not possible at all and PHP+SQL is pretty much the only reliable way to do it then I guess I’ll have to do it in PHP+SQL.

    FWIW, I was looking to do it in the shortcode to have something more portable in the likelihood that I end up in the future having to work with WP installs that don’t allow me as much access to go a PHP or full plugin route. I am otherwise very comfortable working directly with PHP and SQL to make things happen and very often need to do that anyways. I guess the real request here is asking for built-in support for custom taxonomies to not only have their parent’s term_id accessible but technically their whole ancestry as some sort of taxonomy.ancestors array of full taxonomy objects or something and for the shortcode to allow such a query (e.g. taxonomy.ancestors HAS-SLUG 'slug-name' or 'slug-name' IN taxonomy.ancestors.slug or something). I know I could code this in PHP, but it would certainly be a nice-to-have

    Thanks again for your advice, Jory, and Pods is still a great solution to the common problem of needing many custom types in a WordPress!

    • This reply was modified 3 years, 11 months ago by Alex R. Reason: Added clarification
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @apollolux

    I understand what you mean but at this point it would be out of scope for Pods. Such features would make the shortcodes and find() method way more complex than they are now. These are such edge cases that we would advice users to go a custom PHP route for such features.

    Cheers, Jory

    Thread Starter Alex R

    (@apollolux)

    No worries, thanks again!

    Hi @apollolux,

    I don’t know, whether you have found a solution so long. Since I was faced with the same problem, I experimented a bit.
    My solution: the where clause cannot check whether the parent of the current taxanomy term points to the category you are looking for.
    Instead, they should check whether the current term is a member of the set of all child terms of the category.

    where="placement.term_id in (SELECT b.term_id FROM wp_terms a JOIN wp_term_taxonomy b ON a.term_id=b.parent WHERE a.slug='featured')"

    Regards,
    Friedbert

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shortcode WHERE for custom taxonomy parent name/slug?’ is closed to new replies.