WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
Sorting / Filtering Within Content Types (2 posts)

  1. foochuck
    Member
    Posted 1 year ago #

    I'm really loving this plugin. I'm using the summarize posts option which works great, but I'm looking to expand upon it.

    Trying to figure out how I can filter content within a content type.

    For example, I have a list of "celebritys" on my website. I'd like to give users a drop down menu so they can filter celebritys by letter. For example, if they choose the letter "C" from the drop down, all users with the letter "C" in their last name would display.

    In addition I'd like to also be able to filter the data in my celebrity content type to show most recently added celebritys to my site.

    -foo

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

  2. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    Glad it's useful to you. When you define a relation field, you get some access to the filters available with GetPostsQuery, but not everything ... it's hard to come up with a visual filtering form that's not overwhelming.

    Re filtering: It's tough to do iterative filtering like that in the manager (i.e. where one form action controls another). I've consciously avoided doing that in the manager because it's very difficult to standardize things like that in a sensible way for mass-use.

    However, I think really what you're after is for the front end... With the PHP version of summarize posts (i.e. GetPostsQuery's get_posts() function), you can specify operators (see http://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_posts#Operators)

    A trick you could do is to create a dedicated page for searching AND create a dedicated page template where you can house your PHP code (the best thing about pages is that they can have a dedicated template for individual pages). Then in your template, you can do something like this:

    <?php
    $args = array()
    $args['post_type'] = 'celebrities';
    
    if (isset($_GET['letter']) && !preg_match('/[^a-z]/i', $_GET['letter'])) {
        $args['post_title']['starts_with'] = $_GET['letter'];
    }
    
    $Q = new GetPostsQuery();
    $results = $Q->get_posts($args);
    foreach($results as $r) {
        // print links to each celebrity
    }
    ?>
    
    Click a Letter!:
    
    <a href="?letter=A">A</a>
    <a href="?letter=B">B</a>
    <a href="?letter=C">C</a>

    Something like that -- I haven't checked the regular expression there, but the point is to sanitize your data so you're sure that the input is in fact a letter and not something like

    http://mysite.com/search/?letter=<malicious_code_here>

    Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic