0
votes

I have created a custom post type using "Types" plugin. The post type has some custom taxonomy and fields.

I want to query this post type using raw sql because I have to do some sorting and filtering based upon user request.

How can I do it using raw sql query?

A sample query would be extremely helpful. Thanks!

1
Do you have more information to provide? - devasia2112

1 Answers

1
votes

Please defer to http://codex.wordpress.org/Post_Types

Specifically,

Querying by post type

You can also create new queries to display posts from a specific post type. This is done via the "post_type" parameter to a WP_Query.

Example:

$args = array( 'post_type' => 'product', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_title();
    echo '<div class="entry-content">';
    the_content();
    echo '</div>';
endwhile;

This simply loops through the latest 10 'product' custom-post types and displays the title and content of them.


As you can see form the above, your custom post types are stored in the same table as regular posts (and pages) they just have their post_type column set to your post type.