Search This Blog

Sunday, 24 February 2019

Get Post By Meta value in wordpress.

function getPostByMetavalue(){
// the meta_key 'diplay_on_homepage' with the meta_value 'true'
$args = array(
    'post_type'        => 'product', //your custom post type name
    'meta_key'         => '_regular_price', //Meta key what do you want to search by key.
    'meta_value'       => 50, // Meta Values
'posts_per_page'   => -1 // Post per page -1 means show all post you can add your choice like 10 or 5...
);
$query = new WP_Query( $args );
echo "<pre>";print_r($query);echo "</pre>";
}
add_shortcode('getPostByMetavalue_short','getPostByMetavalue');

No comments:

Post a Comment