Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress get post slug

<?php
    global $post;
    $post_slug = $post->post_name;
?>
Comment

How to get a WordPress post by slug

function get_post_by_slug($slug){
    $posts = get_posts(array(
            'name' => $slug,
            'posts_per_page' => 1,
            'post_type' => 'product',
            'post_status' => 'publish'
    ));
    
    if(! $posts ) {
        throw new Exception("NoSuchPostBySpecifiedID");
    }

    return $post[0];
}
Comment

PREVIOUS NEXT
Code Example
Php :: pdo last id 
Php :: wc order details 
Php :: get url parameters in laravel blade 
Php :: check if number is multiple of 3 in php 
Php :: php array length 
Php :: php get and print file contents 
Php :: convert to int php 
Php :: php version compare function 
Php :: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65015808 bytes) 
Php :: loop index foreach laravel 
Php :: php get query string 
Php :: test curl php 
Php :: php shell script 
Php :: wp get category by id 
Php :: laravel/framework[v8.75.0, ..., 8.x-dev] require league/flysystem ^1.1 - satisfiable by league/flysystem[1.1.0, ..., 1.x-dev]. 
Php :: php random name 
Php :: php count amount of times a value appears in array 
Php :: ob_start in php 
Php :: laravel migration seed fresh 
Php :: woocommerce order get_data() 
Php :: php turney if 
Php :: woocommerce check if user is logged in 
Php :: laravel with has 
Php :: Download multiple files as zip in PHP 
Php :: yii app db createcommand join yii1 
Php :: mysqli loop 
Php :: get url with php 
Php :: searching inside a file using php 
Php :: wherebetween date laravel 
Php :: laravel query select from table where id != to another table id 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =