• Hi,

    I have a problem with my cat IDs….

    I want to know if there is a possible reason why one category is showing before one and on the other post the order changes.

    Here an example. In my foreach I get this for the first post

    echo $current->cat_ID . ' ';
    10 17

    and in my other post I get this

    echo $current->cat_ID . ' ';
    18 16 10

    If you check the first post get 10 then 17 but on the other, I get 18 16 then 10.

    How is that possible?

    EDIT #1 : Can I change the date of creation on the category?

Viewing 3 replies - 1 through 3 (of 3 total)
  • To answer your edit, not that I know of.

    If the order of your categories is important, could you run them through a query? I’d think you’d be able to order them however you wanted to then….

    Thread Starter Patrice Poliquin

    (@poliquinp)

    Actually, I have this code.

    I will explain my problem a bit more.. I have a page single where we see normals articles.

    I want to show a special link if the post is in category 10.

    But when I make my detection it only get the last catID. This is why I need to change the order.

    <?php 
    
    if (have_posts()) : the_post(); 
    
    	$category = get_the_category();
    	$agenda = false;
    	$selected_category = 0;
    	foreach($category as $current)
    	{
    		$myCat = $current->cat_ID;
    
    		// Do not care
    		if($myCat == 12) { $agenda = true; }
    		elseif($myCat != 9)
    		{
    			$selected_category = $myCat ;
    		}
    		// End of Do not care		
    
    		echo $current->cat_ID . ' ';
    	}
    
    endif;
    ?>

    not tested, but something like this might do the trick…..

    $ten_cat= new WP_Query();
    $ten_cat->query('cat=10');
    if($ten_cat->have_posts()):$ten_cat->the_post();
      //doWhatYouDo
    else
      //whatever

    I mean, if the goal is to post something when the category is 10, that’s probably the way I would do it. But perhaps I don’t understand the question and/or this won’t work

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘cat_ID order problem’ is closed to new replies.