Support » Fixing WordPress » Get the posts from multiple categories

  • Resolved mvanboordt



    I have this weird thing I just can’t get my head around.

    All my posts are filled under a categorie.
    On my homepage I have a ‘custom’ widget that loads the 5 latest posts with the categorie of my choosing.

    Now I have installed a plugin that also uses categories.
    I would like to get posts from the two categories based on time to show on my homepage.

    I’ve come a long way but I can’t get the posts from the plugin.

    I hope anyone can help me.
    Here goes:
    Plugin: Job Manager

    This is my custom widget/ WP_Query:

    function widget( $args, $instance ) {
    		extract( $args );
    		function list_all_posttypes() {
    		global $post;
    		global $wp_query;
    		echo '<ul>';
    		$wpcust = new WP_Query(
    				'post_type' => array(
    				'category_name' => 'news,jobs',
    				'showposts' => '4' )
    			// the $wpcust-> variable is used to call the Loop methods. not sure if required
    			if ( $wpcust->have_posts() ):
    				while( $wpcust->have_posts() ) : $wpcust->the_post();
    				$displayenddate = get_post_meta( get_the_ID(), 'displayenddate', true );
    				$displaystartdate = get_post_meta( get_the_ID(), 'displaystartdate', true );
    				if( '' != $displayenddate && strtotime( $displayenddate ) <= time() ) {
    				$my_post['ID'] = get_the_ID();
      				$my_post['post_status'] = 'draft';
    				//unset( $jobs[$id] );
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    		echo '</ul>';


Viewing 3 replies - 1 through 3 (of 3 total)
  • Two things spring to mind:

    1. ‘category_name’ is really a misnomer, as it actually looks for the category’s slug, so make sure that you’re using the slug rather than the name.

    2. Are these normal post categories, or are they custom taxonomies? If so, ‘category_name’ will only pull in normal categories and you’ll have to use the taxonomy parameters instead.

    Hi Peter,

    1. I learned that the hard way 🙂 but didn’t made any changes
    2. I assume it is a taxonomy, however the plugin isn’t very clear.
    I can see the reference of the category in the WP_terms table in the database but if I use:

    'taxonomy' => 'taxonomy_name',

    It still doesn’t work

    I’ve got it fixed for now because it allready worked. The purpose was to exclude a certain category. So I used 'cat' => '-ID', and this worked

    So I quess this is resolved 🙂


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get the posts from multiple categories’ is closed to new replies.