Creating a custom GUID while inserting the post - php

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'");

Related

How to create duplicate Wordpress post content using wpdb query?

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.

Get ID's of multiple inserted rows (Laravel)

is it possible to receive the id of multiple inserted rows?
I know that after saving ($post->save()) the post object will receive an id after save. But what if I have inserted array of posts? will I get their id's too?
I am asking this because I am trying to create a many new posts which has many comments (each post may have zero or many comments). Both the posts and the comments are not yet created in the DB.
For this I want first to save the posts and then save the comments. Not sure if it is the best way though...
Thanks!
If you use loop for inserting post, Probably in each iteration you can get new id!!!

keeping track of deleted posts without using wordpress functions

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.

WordPress - Taxonomy MetaData RETRIEVE

I am using https://github.com/bainternet/My-Meta-Box to create MetaData in my taxonomy "group"
How do I retrieve that data? As of right now I have each group ID, but i have no idea how to retrieve the MetaData.
Just figured it out. Unfortunately, https://github.com/bainternet/My-Meta-Box Uses the WP_Options table in the database, not the Meta table, like it should.
Here is how to get the information.
<?$meta = get_option('tax_meta_'.$category->term_id)?>

creating slug in wordpress while inserting data from csv

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

Categories