So, here's what I did. I checked out the existing functionality which is most likely the same of what I wanted to achieve get_page_by_title then from there I was able to arrived a new function get_page_by_slug that will retrieve the page information from a slug.
Please see below, hope this helps a lot on building your wordpress site and hopefully this would be included on the next version of wordpress.
/**
* Retrieve a page given its slug.
* @uses $wpdb
*
* @param string $page_slug Page slug
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
* @param string $post_type Optional. Post type. Default page.
* @return WP_Post|null WP_Post on success or null on failure
*/
function get_page_by_slug($page_slug, $output = OBJECT, $post_type = 'page' ) {
global $wpdb;
$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s", $page_slug, $post_type ) );
if ( $page )
return get_post( $page, $output );
return null;
}
Please take note that you use this as well on retrieving post coz technically, page and post are the same but with different post type, you just need to pass on third parameter as "post". To make it much clearer with names, please see get_post_by_slug function below.
/**
* Retrieve a post given its slug.
* @uses $wpdb
*
* @param string $slug Post slug
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
* @param string $type Optional. Post type. Default page.
* @return WP_Post|null WP_Post on success or null on failure
*/
function get_post_by_slug($slug, $output = OBJECT, $type = 'post' ) {
global $wpdb;
$post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM
$wpdb->posts WHERE post_name = %s AND post_type= %s", $slug,
$type ) );
if ( $post )
return get_post( $post, $output );
return null;
}
My site use this get_page_by_path('your-slug-pos');
ReplyDeleteamaperfect.com
Customer service is the service that you provide your clients. Currently a customer or a client is someone who purchases a service or a product from your organization. Customer service is the very crucial part of a business and really basic. Just making someone feel client. Helping them solve any queries they worries or have, and only looking after their demands.
ReplyDeletehttps://servicecenterguru.com
A long time ago, when someone said WordPress, everyone automatically thought of blogging. While it is still the best solution to use for blogging, it has come a long way and has become a very comprehensive Content Management Suite used to power many different types of websites, including business sites, job boards, sites featuring classified ads, etc.https://medijo.lt/lankstinukai/
ReplyDeleteThank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. make a website
ReplyDeleteOnce you have your hosting, and they've told you how to upload your files (FTP), then you should proceed to setting up a MySQL database, so WordPress can store all of your content.wordpress maintenance service
ReplyDeletehi was just seeing if you minded a comment. i like your website and the thme you picked is super. I will be back. Themify review
ReplyDeleteThe substance that you make is put away in a database neuronto deepl wordpress plugin
ReplyDeleteIncredible articles and awesome design. Your blog entry merits the greater part of the positive input it"s been getting. wordpress
ReplyDelete
ReplyDeleteHello,
we provide affordable and result-oriented SEO services, please give a chance to serve you.
Thanks
Admin: E07.net
You have outdone yourself this time. It is probably the best, most short step by step guide that I have ever seen. wordpress plugin
ReplyDelete