how can i get all object_id’s from the wp_term_relationships where term_taxonomy_id is IN(1,2) AND NOT IN(3)
Means…
object_id term_taxonomy_id term_order
1 1 0
1 2 0
1 3 0
2 1 0
2 2 0
3 1 0
3 2 0
4 1 0
5 1 0
5 3 0
I need the get object_id 2 and 3
SELECT c1.object_id
FROM wp_term_relationships AS c1
INNER JOIN wp_term_relationships AS c2 ON c1.object_id = c2.object_id
WHERE c1.term_taxonomy_id = 1
AND c2.term_taxonomy_id = 2
Works, but i don’t know how to exclude term_taxonomy_id 3
Thanks!
]]>Quick example: Any post that has “Europe” in either the post_content or post_title should be tagged with “Europe”.
I’ve gotten as far as to be able to get all the post_id’s from all posts that need to be tagged, I got the id of the post_tag “Europe”, and if it doesn’t exist I will first insert it and then get the ID, but I’ve come across a problem.
The problem is: when I update the tables:
wp_terms
wp_term_taxonomy
wp_term_relationships
To completely match what is needed, this meaning:
– (optional: insert into wp_terms if not exists) and get the term_id
– (optional: insert into wp_term_taxonomy if not exists) and get the term_taxonomy_id
– (optional: insert into wp_term_relationships if not exists AND increase the “count” in wp_term_taxonomy by 1)
However! wordpress does not tag the post, but everything in the database is correctly edited/inserted….
What am I not seeing?
]]>So I have a new custom post type, with custom taxonomy (aka custom categories)
I poped in a few posts, then hit EXPORT (to get a base XML file to build an importer)
I noticed if you export a blog post from a normal category each “item” has a category:
<category><![CDATA[Uncategorized]]></category>
However exporting custom “items”, with the custom taxonomy is exported in the channel there is no linking of the ITEM to their specific taxonomy.
Is there a way to add this into the exporter? Both my register_post_type() and register_taxonomy() include the line ‘can_export’ => true, but doesn’t seem to help (at least not for what I need)
I did an import of 150 “items” … everything works, all custom data etc, except I had no way to set the relationship between the “item” and the “custom – term_taxonomy”
Anyone else notice this?
It makes it impossible to export all my custom posts & import them back into the right custom taxonomy
Or .. am I really missing something here?
Any help MUCH appreciated
I got this working by performing a delete in term_relationships followed by an insert.
This plugin then hooks into new_to_publish etc and this works fine.
What I noticed is that this way , the count in the wp_term_taxonomy is not maintained.
Are there functions that I can use to manipulate the categories of a post instaid of direct database access and that maintain the count of the category ?
]]>I thought I could figure it out, but because of the way WP stores categories among the terms, term_relationships, and term_taxonomy tables, I couldn’t.
To be more specific, I’d like to search my posts for any occurrence of the word “embed” and put those posts in the “video” category.
Is this possible? If someone can offer a MySQL query to do it, or point me in the direction to figure it out, I’d be grateful!
]]>global $wpdb;
$rand_posts = $wpdb->get_results("
SELECT * FROM $wpdb->posts AS p,
$wpdb->post2cat AS c
WHERE p.ID = c.post_id
AND c.category_id = 4
AND p.post_status = 'publish'
ORDER BY RAND()
LIMIT $num"
);
But now the new wordpress has moved to the post2tag database fields as well as taxonomy etc i’m completely lost on how to update that (and other parts of my website) to reflect.
How does a category now link to a post ?
Can anyone offer any assistance ?
]]>