How to get full slug, including all parent pages
This would replace domain.com/top_page/sub_page/sub_sub_page with /top_page/sub_page/sub_sub_page $path = str_replace(home_url(),”,get_permalink());
This would replace domain.com/top_page/sub_page/sub_sub_page with /top_page/sub_page/sub_sub_page $path = str_replace(home_url(),”,get_permalink());
Pass the desired archive slug via has_archive: $args = array( ‘rewrite’ => array( ‘slug’ => ‘case-studies’ ), ‘has_archive’ => ‘testimonials-case-studies’, );
The easiest workaround could be: function myplugin_update_slug( $data, $postarr ) { if ( ! in_array( $data[‘post_status’], array( ‘draft’, ‘pending’, ‘auto-draft’ ) ) ) { $data[‘post_name’] = sanitize_title( $data[‘post_title’] ); } return $data; } add_filter( ‘wp_insert_post_data’, ‘myplugin_update_slug’, 99, 2 );
It’s only Pages where this is an issue. Posts are fine. Seems like a bug to me, but regardless of whether or not it’s a bug, you can not use numeric slugs on pages. This is because number slugs like “/750/” interfere with posts years “/2010/” etc. and WordPress can’t tell the difference. If you … Read more
This is what you’re looking for, tested and I use it on my own sites: function the_slug_exists($post_name) { global $wpdb; if($wpdb->get_row(“SELECT post_name FROM wp_posts WHERE post_name=”” . $post_name . “””, ‘ARRAY_A’)) { return true; } else { return false; } } You can then use it like this: if (the_slug_exists(‘contact’)) { // do something } … Read more
Due to wp_posts table structure the length of post_name column (the column for slugs) is equal to 200 characters.
The function you are looking for is get_term_by. You would use it as such: <?php $term = get_term_by(‘slug’, ‘my-term-slug’, ‘category’); $name = $term->name; ?> This results in $term being an object containing the following: term_id name slug term_group term_taxonomy_id taxonomy description parent count The codex does a great job explaining this function: https://developer.wordpress.org/reference/functions/get_term_by/