Ready to get started?Download WordPress


in_category help (2 posts)

  1. artinh82
    Posted 5 years ago #

    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]

  2. MichaelH
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic