Forums

[resolved] List posts taxonomies without knowing what they are in advance (3 posts)

  1. Dale Sattler
    Member
    Posted 1 year ago #

    I've built a Actionscript - AMF - PHP - WordPress bridge, that lets Flash use WordPress as a CMS.

    When building what I call a PostVO object, (which is basically a representation of a post within the database with some extra values added on. Which are categories, post_tags, attachments, featured image and permalink) I've come across a slight hurdle with getting a list of the taxonomies the post belongs within. I can access them via get_post_taxonomies which gives me a list of possible taxonomies, but not the particular ones associated with a particular post.

    get_post_taxonomies is a start, and I can run a for each loop against what this returns, using wp_get_object_terms to check if the post has that particular taxonomy.

    But it seems a little inefficient. I can access each posts taxonomies via a SQL query. Ideally however I try to resist working directly on the database and prefer to use the WordPress API.

    So, is there a function I can call that returns the taxonomies of a particular post, without knowing what those taxonomies are in advance?

  2. Dale Sattler
    Member
    Posted 1 year ago #

    Heres the basic SQl query;

    SELECT taxonomy
    FROM wp_terms
    INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
    INNER JOIN wp_term_relationships  wpr ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
    INNER JOIN wp_posts p  ON p.ID = wpr.object_id
    AND p.post_type =  $postType
    AND p.ID = $postId
    ORDER BY object_id
  3. Dale Sattler
    Member
    Posted 1 year ago #

    In the end I just used that SQL query to return an array of taxonomy names, which I pass to get_the_terms.

Topic Closed

This topic has been closed to new replies.

About this Topic