Custom Content Type Manager
[resolved] get post's category (2 posts)

  1. videlalla
    Posted 2 years ago #

    I'd like to build a page with one kind of my custom posts: I used the summarize_posts function, and half work is done.
    [summarize_posts post_type="project"]


    The next step is to use different color for the different categories for this kind of custom posts, but I don't want to create 3 different summaries, I'd like to find the category for every post. Something like this:
    <li class="[+post_category+]">

    Is there a way to do this?

    Thanks a lot


  2. fireproofsocks
    Plugin Author

    Posted 2 years ago #

    No, this isn't possible via the shortcode. You'd have to do it using the PHP equivalent in your template file and use WP's various functions for getting category and tag info. The reason is that it's not a 1:1 relationship between a post and a category. A post can be placed into MANY categories, so you're not longer dealing with a simple string, you're dealing with a list (i.e. an array). So simple [+placeholders+] are not enough: you'd have to describe your rules and preferences for how to sort and join the items in that array -- that's much better suited to PHP.

    Secondly, although you can filter on taxonomy data using Summarize Posts (e.g. select all posts in category X), the query does not return this data. Summarize Posts deals primarily with data inherent in the post (i.e. the post's regular and custom fields), not with the ancillary data that classifies posts (i.e. tags and categories). This is a worthy feature request, but the overhead when joining on an unknown number of virtual tables (i.e. categories, tags, custom taxonomies) makes its potential integration problematic.

    To solve your problem here, you could create a dedicated template in your theme directory (copy your current page template), tell your page to use this template, and then add the necessary PHP into that template file.

    Or, another alternative may be to use a simple custom field (e.g. a dropdown field) instead of a category and treat that as your "category". Since a dropdown field stores a simple string, it WOULD work with the placeholder scenario you described. You wouldn't get the built-in WP searching and widget support that a full-blown taxonomy would get, but it would solve your immediate problem.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Content Type Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic