2

I am running a simple wp query to retrieve just one post.

But the post is a custom post-type post, not a normal post

$ajaxBike = $_GET['varbike']; 

$bikeProfile = new WP_Query(array(

    'name'          => $ajaxBike,
    'meta_query'    => array(
        array(
            'key' => 'app_visibility',
            'value' => 1,
            'compare' => '='
        )
    )

));

or...

$ajaxBike = $_GET['varbike']; 

$bikeProfile = new WP_Query('name='.$ajaxBike);

But I think the name parameter only works for posts. But I'm struggling to find anything to work with a custom post type slug.

Can you anyone help work out how to query a custom post type using the slug?


Thanks in advance!

1 Answer 1

6
'post_type' => 'custom post type slug'

By default 'post_type' is set as 'post', you will need to specify your custom post type in any query you make.

In future refer here:

http://codex.wordpress.org/Class_Reference/WP_Query

1
  • 1
    This worked great thank you. Just added 'post_type' => 'on-road' and it pulled it in :-)
    – Joshc
    Commented Nov 20, 2012 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.