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
Post a Comment