Support » Plugin: Custom Content Type Manager » Summarize Posts shortcode – coding issue

  • Resolved akadis2


    I can’t figure out how to properly code the summarize posts shortcode when it includes meta-values from an multi-select custom field.

    This is my code:

    [summarize-posts post_type=”resource” meta_key=”location” meta_value=[“National”] limit=”600″ order=”ASC” orderby=”post_title”]

    Since the value of the multi-select field is stored in brackets in the DB, using the brackets within the summarize-posts code, doesn’t work properly.

    In addition, when more than two values are selected, how can I use the sumamrize-posts shortcode, to only display results from one of the values?

    Thanks so much… I’ve been trying to figure this out for more than a month!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor fireproofsocks


    You need to use the PHP version of the query: the shortcode version is quite limited in comparison, mostly due to the limitations, whoops I mean FEATURES of the WordPress shortcode syntax.

    I’m not sure what you mean by “display results from one of the values”, but I think you probably need to do a LIKE comparison — the shortcode only lets you do an EQUALS comparison. In php:

    // in a theme file far, far away....
    $Q = new GetPostsQuery();
    $args = array();
    $args['post_type'] = 'resource';
    $args['location']['like'] = '"National"'; // <-- note the quotes here
    $results = $Q->get_posts($args);
    foreach ($results as $r) {
     // ... etc...

    Because CCTM stores multi-values as JSON arrays, you have to compare against the double-quotes to properly delimit your values, otherwise a term like “National” might also include results using a term like “National Parks”. Note too that you can name your custom fields: you don’t need to use the meta_key/meta_value syntax.

    There are lots of examples in the wiki.

    Thanks for your super prompt reply. Yes, a comparison would work nicely.

    My main question now, is where do I add this php code? The way I am using cctm is to add “resources” to the DB, then I created posts that I called “views” to display the resources based on the values stored for each custom field. Then using a widget, I created a menu of all those “views”

    For example, this is one of the “views”

    ANd on the right side, you can see the menu of all resources.

    Plugin Contributor fireproofsocks


    Now you’re seeing some of the limits of wordpress. Here’s how I get around them: I create a page (not a post) as my unit here because pages can have a dedicated theme file — copy the page.php file in your theme and give it a unique name in its comment block, e.g. “Template Name: My View”. Then you can select that template when you create a page. Put your PHP in there. That’s how you can connect a page to a specific file containing your specific php.

    Thanks again… I’ve created my new template file page-myview.php and added the php code. Of course nothing happens, since I don’t know what to put after this:

    $results = $Q->get_posts($args);
    foreach ($results as $r) {

    // I TRIED ADDING “print $post[‘post_title’];”


    The summarize-posts shortcode was so easy compared to this php coding 🙁

    Plugin Contributor fireproofsocks


    See the wiki: lots of examples there.

    You’re iterating over an array using the $r variable in your case: so you can’t print $post and expect anything to come out of it. Try print $r[‘ID’]; or print $r[‘post_name’]; or print_r($r); to get a full dump of every attribute available to you. Sorry, I can only offer some pointers here — some PHP knowledge is required and it’s not practical/efficient/sensible for me to repeat a PHP 101 course inside my docs.

    Thanks so much for your help.

    With some study and time I hope to solve this issue.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Summarize Posts shortcode – coding issue’ is closed to new replies.