Support » Fixing WordPress » in_category help

  • Hello,
    I need some help with “in_category”.

    Most of my posts are published in 2 categories. For example
    Post1 – Category: Player Wallpapers, Cristiano Ronaldo
    Post2 – Category: Player Wallpapers, Wayne Rooney
    Post3 – Category: Club Wallpapers, Manchester United

    I’m trying to add a default text to each post, depending on the name of each player or club.

    I’ve tried using the following code, but I’m not sure if I’m doing it right:

    if ( (in_category( 'cristiano_ronaldo' )) &amp;&amp; (in_category('player_wallpapers'))) {
    	echo "Some text about C. Ronaldo";
    } else {
    	echo "No info";

    But all I get for every post is “No info”, even for the posts that have been published under cristiano_ronaldo & player_wallpapers.

    Then I went to my database and noticed that in the table “wp_posts” the value of “post_category” is ‘0’ for all of my posts. I’m not sure if that is normal.

    Thank you,

    [moderated–bump removed. Please refrain from bumping as per Forum Rules]

Viewing 1 replies (of 1 total)
  • Try using the category ID to see if that makes a difference:

    if ( (in_category(‘4’) ) && ( in_category(‘5’) ) {

    The post_category field in wp_posts is no longer used and will be removed in 2.8. The terms/taxonomy tables contain the categories.

Viewing 1 replies (of 1 total)
  • The topic ‘in_category help’ is closed to new replies.