I've created a demo website where I want every post to have the same content. I've created 50 posts through a random post generator plugin. I have edited one post's content. Now is there a way to copy the content and paste to all 49 other posts?
E.g. I used this query to duplicate the excerpt.
$wpdb->query( "UPDATE wp_posts SET post_excerpt='This is an excerpt for the post' " );
Looking for a similar query. Please guide.
Related
I'm trying to receive all portfolio entries from the database. I want to list this and also link the WordPress path to it. This is the SQL query:
SELECT id, post_title, post_name FROM 1bncopo2_posts WHERE post_type='portfolio';
post_title could be the following:
Mercedes-Benz AMG C63
Mercedes-Benz S500
BMW 650i XDrive
and now post_name for the first entry of the above list is mercedes-benz-amg-c63. However, I found that in my database table, multiple portfolio vehicles (even vehicles by BMW, etc.) have post_name set to mercedes-benz-amg-c63. My idea was to generate the URL to the portfolio item using post_name as an appendix to the wordpress path. TO BE CLEAR: This is going to be a seperate application reading from the WordPress installation's database and trying to make up the corresponding links to the portfolio items.
Now that post_name is not UNIQUE or something I could use, I have two questions:
Why would the WP database allow for duplicated post_names?
How can I get the post (portfolio)'s URL, if not by post_name?
It is impossible to repeat the link, if you see the link from the beginning you will find it different.
If this post (mercedes-benz-amg-c63) for custom post type called (portfolio) you see URL like:
www.domain.com/portfolio/mercedes-benz-amg-c63
But if its post type (post) you see URL like:
www.domain.com/mercedes-benz-amg-c63
Then as you see the URL not duplicated
There are posts which inserted multiple time with post_name like "icegram-2", "icegram-3", "icegram-4" along with "icegram".
Now, I want to remove posts with post_name "icegram-2", "icegram-3".
It's an example. There are more posts like this. I want to delete all such duplicate posts.
Is it possible with mysql query?
You could use the following plugin:-
https://en-gb.wordpress.org/plugins/delete-duplicate-posts/
Maybe have a look at How to delete Duplicate posts in WordPress
If I find anything else I will update my answer.
Delete Duplicate Posts plugin can helpful for you
Ok. Here's the problem.
I am creating 2 posts in here. First one is parent post and second one is a attachment post.I want to create a custom guid while inserting the parent post. e.g.
guid => http://localhost/music/?post_type=pdf&p=1548
I tried inserting the wp_insert_post first and then updating it with the update post function but it didn't work. Can you help me out in here because I am stuck and I am unable to sort,also another related question.
Can you get the current insert id while inserting the post?
Try to use raw sql:
global $wpdb;
$updateguid = $wpdb->get_results("UPDATE wp_posts SET guid ='what you want' WHERE ID ='inserted-id'");
i have 2 wordpress websites A and B.
if A somehow changes (adding a post , editing a post , deleting a post ) , B needs to change as well .
so in A by using a php robot which is checking database every couple of minutes , i,ve created a json feed for added and edited posts of A .
it's easy to track added/edited posts by checking wp_posts table . but i can't find a way to know which posts have been deleted ( Delete Permanently ).
this script is suppose to be portable and usable for people who are not programmer , so i dont want to use wordpress functions or do any change/addition to wordpress system .
so is there any way to find deleted posts by checking the database or something like that ?
You can check for posts in the trash by using the query:
SELECT * FROM `wp_posts` WHERE `post_status` = 'trash'
but if you are trying to find posts that have been removed from the database you will need to either track the missing IDs in the wp_posts table or add some functionality to track when a post is deleted. You can do this by using the delete_post action hook in your theme:
function my_tracking_function() {
// Put ID into new database table
}
add_action( 'delete_post', 'my_tracking_function', 1 );
And then pass that table to the other site for processing. Once both sites are synced you can run a cleanup routine to empty the tracking table. I realize that this is partially using Wordpress functionality, but the passing of the table data can be done outside of Wordpress using SQL.
I have created a plugin to upload the csv to wordpress. what i want to know is how to create the slug of the title while inserting it into wp_posts.
Current i am using normal mysql query to insert the data.
Any help?
Thanks
The post_name column in wp_posts contains the slug. For generating the slug itself use sanitize_title