Friday, September 2, 2016

wp retreving custom post loop


accepted
$loop = new WP_Query( array( 
    'post_type' => 'portfolio', 
    'cat' => 5, // Whatever the category ID is for your aerial category
    'posts_per_page' => 10,
    'orderby' => 'date', // Purely optional - just for some ordering
    'order' => 'DESC' // Ditto
) );

while ( $loop->have_posts() ) : $loop->the_post(); ?>
Couple of things to consider as well :
1) is your custom post type registered to use the built in categories or is it a custom taxonomy that it's using? If the former then the above should work, if the latter then you would need to use 'your-taxonomy-name'=>'your-taxonomy-term' in place of the cat=>5 parameter
2) Do you have any other loops running on the page? If so they will need
<?php wp_reset_query(); ?>
after them in order for subsequent loops 

No comments:

Post a Comment