FaluFluff
Member
Posted 9 months ago #
Hi!
I'm trying to figure out how to run a mysql query from a php-file with a post ID and echo the tags related to that post. I'm only using one tag per post, so i don't need to create an array for them. I've looked everywhere for an example but i can't seem to figure it out.
Can someone please help me?
Thanks!
FaluFluff
Member
Posted 9 months ago #
With this code I get ALL terms, but what it want is only the one associated with my post.
$postId = 167;
SELECT slug
FROM wp_terms
INNER JOIN wp_term_relationships
ON (wp_term_relationships.object_id = '$postId')
INNER JOIN wp_term_taxonomy ON (
wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
AND wp_term_taxonomy.taxonomy = 'post_tag')
I can't figure it out!
FaluFluff
Member
Posted 9 months ago #
Does this work even if my php-file is located on a whole different server?
you'll need to load the whole wp environment. but if your host allows remote database connections, it'll work.
FaluFluff
Member
Posted 9 months ago #
Thanks for your help! I tried the JSON API for WordPress and it works perfectly for my needs.