I have more than one category name in the post and I want to change specific primary category name to be normal category and then normal category to be primary category.
Let's say I have sponsored category and fashion category. So, I want to switch fashion category to be primary category because I do not want to show /sponsored/ in the URL.
Take Note: I have thousand of posts and I cannot switch the category name manually.
Using SQL and PHP you can run a foreach loop with all posts id that need to be updated.
A good starting point is an Excel file with all posts and its category ids that will be set as primary, so convert the spreadsheet to a json file to use in the PHP loop.
Below is the SQL query to do this:
UPDATE wp_postmeta SET meta_value = $new_primary_id WHERE post_id = $post_id AND meta_key = '_yoast_wpseo_primary_category';
Where $new_primary_id is the id of the category that will be set as primary, and $post_id
is the post id that will be updated.
If you using Yoast SEO Plugin there is the solution for you check here.
https://wordpress.org/support/topic/bulk-change-primary-category/
Related
I am working on a Woocoomerce site with many categories.
I have to add some text at the end of the categories (suffix) slug. Like "klm".
How to change product category slug in bulk in Woocommerce?
For example,
Furniture > Kitchen Furniture
The permalink for the category is as follows:
"kitchen-furniture"
What I want to do is add a new text (suffix) to the end of all (main category or subcategories).
For example,
"kitchen-furniture-klm"
Yes, this can be done from wp-admin>Products>Categories. However, as I said at the beginning, there are many categories.
There are 22 pages of entries for categories on Stackoverflow. I've looked at almost all of them. However, I couldn't find what I was looking for. I would appreciate if someone could guide me where to start.
Note: Please take database backup before execute following update query
You can do this in database, using following query
UPDATE wp_terms SET slug = CONCAT(slug, '-klm') WHERE term_id IN(SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = 'product_cat')
I'm using
<?php query_posts('cat=34546&posts_per_page=5&order=DESC');
in order to get five posts from a certain category. The order is determined by the ID of the post. I would like it to be determined by another field, like post_date column in posts (let's say for the sake of this question that I manually change post_date that in the database). How can this be done?
Using the Query Posts orderby parameters.
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
For example:
<?php query_posts('cat=34546&posts_per_page=5&order=DESC&orderby=date');
The reference I linked above has what values you can use for orderby.
I have created CPT using CPT UI plugin and suddenly I lost all the important data. I don't have any backup and I need it backup. Is there any I can get it backup? I have SQL backup of last week.
Moreover I am seeing Count on CPT categories but they are showing Empty on main CPT page. for example CPT:
Animals --> showing (0) posts
Animal Categories is showing 100 counts that means It has data but something has hide it. I remember I updated Permalinks but I don't remember the previous settings
use this sqlQuery in your SQL Database (phpMyadmin or ...) and you will get a list of your custom post type posts with their info:
SELECT *
FROM {table prefix}_posts
WHERE post_type = 'your_custom_post_type_name'
AND post_status = 'publish'
your {table prefix} can be wp or some thing else if you've change it on wp setup step you can check it in your Database or wp-config.php file in your wp root.
you can replace * in query with whatever field name you want for example:
post_content, post_title, post_excerpt
to only get fields that you need.
Currently our site's videos are posted as custom post type. We have totally changed the theme and added so many new features. For our new site we are trying to change videos to category. (Custom post type to normal categories). Is this possible. I have exported the custom post type as XML file, but I don't know how to change it to categories.
Finally an answer. Before I start These are the conditions I'm using.
The Custom posttype (called video) need to be merged into the default post
Video's has it own custom categories, who needs to be merged into the default categories
All Video's need to get a category video, the old categories need to be children of the newly created video category.
Step Zero: BACKUP my sql BACKUP
First create a the video category in the default posttype. Note it's ID (it is found in the category edit page in the url under tag_ID. I'm assuming ID 4 in my examples
Second we assign this category to the video posttype with the following Sql:
INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`)
SELECT `ID`, '4' FROM `wp_posts` WHERE `post_type` = 'video';
Next we assign the existing custom categories as children. You need the video category slug, found on the custom-category page agian in the url with taxonomy.
UPDATE `wp_term_taxonomy` SET `parent` = 4, `taxonomy` = 'category' WHERE `taxonomy` = 'VIDEO CATEGORYSLUG';
The last step is assigning the normal posttype to the custom posttype.
UPDATE `wp_posts` SET `post_type` = 'post' WHERE `post_type` = 'video';
Now it should be done and everything should be merged. So TEST TEST TEST.
After that the code making the posttype can be disabled.
This should work, if you have questions just ask.
I have 5 blog sections each representing a category. However, I would like to have a category called "all" that if checked would include the post in all 5 section without having to click every category.
I guess the only way to do this is to add something into the blog category template file to tell it to include the usual category posts as well as the "all" category.
now I think i've located where it queries the post:
if ( $wp_query->have_posts()) : while (have_posts()) : the_post();
but there is nothing identifying the current category id, except for a few things above for specifying the right title for the theme.
What would be the best way of achieving what I have explained?
You can interact with the wp_query object... the same way that you interact with query_posts()... it accepts the same arguments.
For either you can use Category Parameters as follows (from the wordpress codex: query_posts function reference)
Category Parameters
Show posts associated with certain categories.
cat (int) - use category id.
category_name (string) - use category
slug (NOT name).
category__and (array) - use category
id.
category__in (array) - use category
id.
category__not_in (array) - use
category id.
When it references $wp_query, the variables of the query have already been defined, you can set up your own query with any parameteres you want.