WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get the posts from multiple categories (4 posts)

  1. mvanboordt
    Member
    Posted 3 months ago #

    Hi,

    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>';
    		rewind_posts();
    
    		$wpcust = new WP_Query(
    			array(
    				'post_type' => array(
    					'jobman_job',
    					'post'
    				),
    				'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';
    				wp_update_post($my_post);
    
    				//unset( $jobs[$id] );
    				continue;
    			}
    
    			?>
    			<li>
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			</li>
    
    			<?php
    			endwhile;
    		endif;
    			wp_reset_query(); 
    
    		echo '</ul>';
    	}

    M.

  2. Peter vanDoorn
    Member
    Posted 3 months ago #

    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.

  3. mvanboordt
    Member
    Posted 3 months ago #

    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

  4. mvanboordt
    Member
    Posted 3 months ago #

    So I quess this is resolved :-)

    Thnx

Reply

You must log in to post.

About this Topic