WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] Summarize Posts shortcode - coding issue (7 posts)

  1. akadis2
    Member
    Posted 11 months ago #

    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"]
    [+post_title+]
    [+post_excerpt+]
    [/summarize-posts]

    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!

    http://wordpress.org/plugins/custom-content-type-manager/

  2. fireproofsocks
    Member
    Plugin Author

    Posted 11 months ago #

    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:

    <?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.

  3. akadis2
    Member
    Posted 11 months ago #

    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"
    http://civilrightsteaching.org/books-fiction/

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

  4. fireproofsocks
    Member
    Plugin Author

    Posted 11 months ago #

    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.

  5. akadis2
    Member
    Posted 11 months ago #

    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 :(

  6. fireproofsocks
    Member
    Plugin Author

    Posted 11 months ago #

    See the wiki: lots of examples there. https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_posts_examples

    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.

  7. akadis2
    Member
    Posted 11 months ago #

    Thanks so much for your help.

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

Reply

You must log in to post.

About this Plugin

About this Topic