Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to use a shortcode to display a loop of posts from a category. I have the shortcode working but it is only displaying the actually category names within the custom post type and not the actual posts. Below are the basics:

Custom Post type is "business" Taxonomy is "business_taxonomy" Category made within the CMS is "dfa"

The shortcode code is

add_shortcode( 'list-posts', 'rmcc_post_listing_parameters_shortcode' );
function rmcc_post_listing_parameters_shortcode( $atts ) {
    ob_start();

    // define attributes and their defaults
    extract( shortcode_atts( array (
        'type' => '',
        'order' => 'date',
        'orderby' => 'title',
        'posts' => -1,
        'category' => '',
    ), $atts ) );

    // define query parameters based on attributes
    $options = array(
        'post_type' => $type,
        'order' => $order,
        'orderby' => $orderby,
        'posts_per_page' => $posts,
        'category_name' => $category,
    );
    $query = new WP_Query( $options );
    // run the loop based on the query
    if ( $query->have_posts() ) { ?>
        <h5><?php the_title() ?></h5>
    <?php
        $myvariable = ob_get_clean();
        return $myvariable;
    }
}

so in the page I should put [list-posts type="business" category="dfa"] but nothing shows. If I use just [list-posts type="business"] it just lists the category names in the custom post type not the actual posts titles.

share|improve this question
    
This should work, can you check and confirm if the category dfa has posts in it. –  Maruti Mohanty Mar 5 at 6:36
    
is that the full code? I don't see the while(); ... endwhile; of the actual loop. –  Michael Mar 5 at 9:01
    
It comes from here code.tutsplus.com/tutorials/… –  Brad Dalton Mar 5 at 11:00
    
@BradDalton Ya, I was looking at that code and finally got it to work. The code in that tutorial is broken unless you download it, dont use the posted code to edit. –  Packy Mar 5 at 22:12
    
@Packy Please add your solution as separate answer. –  kaiser Mar 23 at 14:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.