How to define "Main" category in posts with multiple categories? (2 posts)

  1. ElPatre
    Posted 6 years ago #

    If I write a post that I assign to multiple Categories I want to set one of them as the "Main Category" so that I can automatically call posts from that category to appear as "related posts" links etc.

    For example using

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php $category = get_the_category($postID);
          $catid = $category[0]->cat_ID; ?>
    <?php query_posts('cat='.$catid.'&showposts=3');

    would always automatically give me the posts from the "alphabetically first" category (if multiple are chosen), which usually is not the category I want, and rewriting the above code for every single post is obviously no solution.

    For example:
    Article: "How to write good WordPress articles"
    Article Categories: "WordPress" and "Article Writing"
    Problem: I only want posts to get displayed from category "WordPress" but because of the alphabetical order posts from "Article Writing" category would get displayed first.

  2. MichaelH
    Posted 6 years ago #

    Might find it easier to use a Custom Field then use that custom field as the category when query posts.

Topic Closed

This topic has been closed to new replies.

About this Topic