Ready to get started?Download WordPress


Dynamically Pull Custom Post (2 posts)

  1. htausch
    Posted 7 months ago #

    How do I replace pulling a post with a certain category to pulling a custom post type with a certain category. I want to leave the ability to determine the number of posts shown by using the theme's widget.

    This is the code I think I need to fiddle with.

    $query = new WP_Query( array( 'cat' =>$slidecat,'posts_per_page' =>$count ) );
    		           	if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();	?>
  2. justclint
    Posted 7 months ago #

    You will want to use 'post_type' in the argument, so using the code above and with a custom post type called 'music' for example, you would do something like:

    $query = new WP_Query( array( 'post_type' => 'music', 'cat' =>$slidecat,'posts_per_page' =>$count ) );
    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

    For more info see the args for WP_Query: http://codex.wordpress.org/Class_Reference/WP_Query


You must log in to post.

About this Topic