creating slug in wordpress while inserting data from csv - php

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

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.

Edit wordpress menĂº from mysql query

I'm trying to insert / modify / delete items from a Wordpress menu from a MYSQL query in a separate WordPress file.
Does anyone know how wordpress menus work at the database level?
They're nothing else than a default postype, specifically: nav_menu_item.
So like the rest of the postypes they are in the post table or wp_posts if you use that prefix.
As all the rest of postypes their meta values are stored in postmeta/wp_postsmeta with the corresponding id.

Creating a custom GUID while inserting the post

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

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)?>

how wordpress can un-slug a title

i still , don't understand , how wordpress can understand what is this url refer to :
www.mysite.com/about-me/
they are using no identifier
if they using slug functions so how they can retain story information or in other word , how they change back the slugged title to select from database
It processes the "pretty" URL and queries the database with that data. Of course slugs are checked to be unique on creation. Details are in the function url_to_postid() in the file wp-includes/rewrite.php.
If you want to directly obtain the id from the slug you can query the database:
SELECT ID
FROM wp_posts
WHERE post_name = '$slug'
you might need to check wp_posts which is the default name, but it depends on the installation.
This is just a guess:
My guess is that they store the titles in a database, and make sure every title is unique. That way, they can do a look-up by title and know which item is coupled to that.

Categories