php - How to get all post from a post type in Wordpress -


i try product database function get_post_types,but empty array:

 <?php     $list=mysql_query("select * wp_posts post_type='product'");     if (empty($list)) {      echo "none";    } ?> 

try with:

$products = get_posts(array(                             'numberposts'   => -1,                             'post_type'     => 'product',                         )); 

check post_type name correct.

this query post type product, published ones, add:

'post_status' => 'publish' 

to array arguments.

from post can lot of information: post image:

$img = wp_get_attachment_url( get_post_thumbnail_id($post->id) ); 

to category of post:

$cats = get_the_category( $post->id ); 

$cats array of terms.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -