I've been searching for hours, either for a plugin or some safe looking SQL to do this, but nothing seems to be exactly what I need...
I have a Wordpress site of approximately 32,000 posts, and we use various tags to help with administration on the back end (i.e. they're not visible on the front end or used for SEO, before anybody comments on too much usage of the same tag). About 30,000 of these posts include the tag 'new', but we need to now tag the remaining ~2,000 to match.
The WP administration panel isn't really up for the task - it would take somebody days to go through and apply a tag to 2,000 posts. Various plugins seem to exist but they don't really do what they claim in the descriptions. And the only SQL I could find that seemed helpful assumes that the tag is new and that I want to apply it to all posts in a single category. I suppose I could delete the existing tag (again, not a fun task with Wordpress' admin panel - it generally crashes after about 30 posts meaning somebody has to sit clicking the button over and over) and then run the SQL to apply a new.
Can somebody point me in the right direction please?
You could run a loop over all of your posts and use wp_set_object_terms() to add the desired tag:
http://codex.wordpress.org/Function_Reference/wp_set_object_terms
I had this problem today too. I tagged all of my posts with the following SQL. (Replace <prefix> with your DB prefix and "GlobalTag" with whatever you want your tag name to be.)
# create a term which will be your new tag
INSERT INTO <prefix>_terms (name, slug) VALUES ("GlobalTag", "global-tag")
# this is what defines the term as a Tag vs Category vs Video Category, etc
# only do this if you are creating the category through SQL, not the GUI
INSERT INTO <prefix>_term_taxonomy (term_id, taxonomy, count)
SELECT
(SELECT term_id from <prefix>_terms AS term WHERE term.name="GlobalTag") as "term_id",
"tag" as "taxonomy",
(SELECT COUNT(*) FROM <prefix>_posts AS posts WHERE (posts.post_status IN ("publish", "draft")) AND LENGTH(post_content) > 25) as "count"
# now tag every post with GlobalTag
INSERT INTO <prefix>_term_relationships
SELECT
id as "object_id",
(
SELECT term_taxonomy_id
FROM <prefix>_term_taxonomy AS term_tax
INNER JOIN <prefix>_terms ON <prefix>_terms.term_id = term_tax.term_id
WHERE <prefix>_terms.name="GlobalTag"
) as "term_taxonomy_id",
0 as "term_order"
FROM <prefix>_posts AS posts
WHERE (posts.post_status IN ("publish", "draft")) AND LENGTH(post_content) > 25
NOTE: you may want to tweak the posts query in here. This tags all posts that are published and/or drafts and that have content that is longer than 15 words.
Related
Background:
I inherited a website with a tremendously bloated product database. There are around 260 actual products which are translated using WPML into English and French which should make it for a total of 520 posts (for each product there is one same SKU two different IDs). However the total count of products in published status is over 720.
I exported all my products and realized that there is a third instance of some products with the same SKU and yet another ID but they are not associated to any category i.e The 'Categories' field is empty.
These are not variants are just ghost instances of the parent products.
Problem to solve:
I need to get rid of those 'ghost' products that have no Categories association. (I do have the list of offender IDs as a CSV)
If possible I would like to understand what those extra products. Can they be untranslated versions of the listing? are they just corrupted/invalid records?
I can do SQL or plugin or whatever it takes.
Difference in Product Count that shows invalid products
Thanks!
I've solved the problem by using the CLI shell in WordPress.
By simply SSHing into the backend I used the following syntax
wp wc product delete <ID> for trashing the product and you can add the --force to permanently delete it.
Having the list of offender IDs I just simply wrote a shell script that executed all the commands sequentially.
Let me start from scratch to describe what I need:
I have a website about games and I want to get some kind of database, so that players can search/filter it (by year, by genre, by platforms, etc.).
What I came to: I store the games in a separate post-type 'games', for them I added to ACF (Advanced Custom Fields) a group of fields with the data I needed (Release date, Genre, Platform, etc.).
I want to do what is called a "game list" (you know various lists Games about pirates, Games about space, tons and tons of lists, so no - it is not category): this is most likely a post in which I want to be able, for example, to do this:
<post content>
Some useful text ...
<h2> Some Headline </ h2>
// this can be a shortcode or block in guttenberg, I'm not very good. specialist
[insert-game-info id = "1"]
Just a couple paragraph of cool text useful for SEO
[insert-game-info id = "2"]
Lyalyalya, and still text, and behind him again game
[insert-game-info id = "3"]
</ post content>
How to make such a thing? It is clear that it is very necessary that there be some kind of dialogue that allows you to choose from the list of games.
I'm researching whether there is already solution, for me it seems that it must be common problem
Depending on your proficiency, I would recommend using the WordPress get_posts function and return the field data with ACF's get_field inside of the foreach.
ACF's get_field allows you to get a value from a specific post like so:
$value = get_field( "text_field", 123 );
I'm trying to sort a query of product custom post type, ordering by the product weight (ASC - from lightest to heaviest). The product weight is entered in a Advanced Custom Fields "field" on the product edit screen.
The query is working fine, except for when the number contains a comma (ex 1,000). It will put a product with a weight of 1,000 at the top of the list (first). So is somehow not looking at the number past the comma, so views it as 1, not 1,000.
Fortunately, I was able to convince my client to leave out the commas and are using the php number_format() to display the comma on the front end.
However, I don't like relying on my client to remember to exclude the comma for the sorting to work correctly.
Is there a way to have WP Query properly sort number values with commas in them? Maybe with an action or filter to remove the comma before saving in the DB and then adding it back once it's displayed in a template file? I really don't have much experience with actions and filters in WordPress yet.
Thanks in advance.
Front end application will use firebase.com as database.
Application should work like blog:
Admin add / remove posts.
There are "home" page which show several articles per page with "Next" and "Prev" buttons and page which show single article.
Also I need deep linking.
I.e. when user enter URL http://mysite.com/page/2/ I need that application show last articles from 10 to 20, when user enter URL http://mysite.com/page/20/ application show last articles from 200 to 210. Usual pagination.
Main question - is it possible to achieve this if use firebase.com.
I read docs at firebase.com, I read posts here. "offset()" and "count()" will be in the future, use priority, in order to know count of items and not load all of them use additional counter.
Based on this I suppose this:
ADD POST action:
get value of posts counter
set priority for new post data equals to value of posts counter
increase value of posts counter
DELETE POST action
get value of priority for post data
query posts data which have value of priority more than priority for post data which will be deleted and decrease their value
decrease value for posts counter
GET POSTS FROM x TO y
postsRef.startAt(null, x).endAt(null, y).on(... and so on)
Thing which I not like in this way are actions for DELETE POST. Because index of posts will be from 0 to infinity and post with less priority is considered as post which was created earlier so if I have 100000000 posts and if I need to delete 1st post then I need to load data for 99999999 next posts and update their priority (index).
Is there any another way?
Thanks in advance, Konstantin
As you mentioned, offset() will be coming, which makes your job easier.
In the meantime, rather than using startAt and endAt in combination, you could use startAt and limit in combination to ensure you always get N results. That way, deleted items will be skipped. You then need to check the last id of each page before moving to the next to find the proper id to start on.
How can one reset the number of post views in order to remove a specific page from appearing in the "Popular" pages Wordpress widget?
Late to the party, I know, but I needed to figure this out today, which I did. So in case anyone else needs to know (for reference, I'm running WordPress version 3.3.1):
Page views are stored in the wp_postmeta table with a meta_key of post_views_count. Here's the query I used to find the views of a single post:
SELECT * FROM 'wp_postmeta' WHERE 'meta_key' = 'post_views_count' AND 'post_id' = 1234
The query returned 2 results. I'm not sure why, but setting the meta_value of both to zero did the job for me.