2

Hopefully someone can help me with this as I've been struggling for a few days.

I've built a form on a page that lets users filter Events by custom taxonomies Type, Period and Duration. These are working individually i.e. the filter shows all posts with either Type=x or Period=y but not combined. Can anyone see why?

Here's my code in Pastie

I'm also trying to figure out how to paginate my results for my custom loop, but can't figure out why it's not working?

Any help massively appreciated.

Thanks

osu

EDIT

Ok, for some reason, I can't use the array method to pass my variables to query_posts() and I'm assuming this is because with the plugin Query Multiple Taxonomies which I need installed for this to work, it only works with the method 'post_type=event&fttype=daily' etc.

Here's my new code which is working:

http://www.pastie.org/1586564

HOWEVER, even though the pagination is working when you first visit the page, after you submit the form, the pagination stops working. So, nearly nearly there, but I need some help with the last part if anyone can be so kind?

Thanks

osu

  • Just a question...do you use fixed terms for your period and duration taxonomies? Can you give me an example for both? I needed something similar, but i decided to go with metadata instead of taxonomies, so i'm wondering if the latter would be better. – wyrfel Feb 19 '11 at 11:38
  • Hi wyrfel, no, I let my client create whatever terms they want in the admin end for each taxonomy (Type, Period and Duration). I then list those terms in the form's select dropdown using the function osu_list_terms('taxonomy-name', $active_option). Here's the function code if it helps: pastie.org/1582561 – Osu Feb 19 '11 at 15:58
  • Thanks for that. I'm still a bit curious, though...so if you let them enter whatever, i'm assuming you either don't use it for calculations or write a parser? I guess that explains why you have separate start and end fields? – wyrfel Feb 19 '11 at 20:05
  • Hi,I'm using Custom Fields StartEventDate and EndEventDate to order the posts by Event Date - these are set using a date picker in the post editor using Custom Field Template plugin. So, I'm using the custom fields to calculate the Event Date relative to today's date, but the terms for my taxonomies Type, Period and Duration can be added like categories in the admin end because they are descriptive, not numerical. If you wantto force some terms to choose from on your site admins, then take a look at the previous post I linked to - there's a link on making dropdowns from meta boxes – Osu Feb 19 '11 at 23:31
1

To fix your "query filters" change

// Set defaults in nothing entered:
if(!isset($_POST['showfilter'])) {
    $ft_args = 'post_type=ftevent&';
    // $ft_args .= 'posts_per_page=1&'; SHOW ALL
    $ft_args .= 'paged=' . $paged . '&';
    $ft_args .= $osu_datecompare . '&';
    $ft_args .= 'orderby=meta_value&order=ASC';
} else {
    // Filter query with multiple taxonomies and paginate results
    $ft_args = 'post_type=ftevent&';
    $ft_args .= 'posts_per_page=2&';
    $ft_args .= 'paged=' . $paged . '&';
    $ft_args .= 'fttype=' . $ft_t . '&';
    $ft_args .= 'ftperiod=' . $ft_p . '&';
    $ft_args .= 'ftduration=' . $ft_d . '&';
    $ft_args .= $osu_datecompare . '&';
    $ft_args .= 'orderby=meta_value&order=ASC';
}

to

// Filter query with multiple taxonomies and paginate results
    $ft_args = array(
    'post_type' => 'ftevent',
    'posts_per_page' => 2,
    'paged=' => $paged ,
    'meta_key' => 'StartEventDate',
    'meta_compare' => '>=',
    'meta_value' => $todaysDate,
    'orderby' => 'meta_value',
    'order' => 'ASC');
    if (isset($ft_t) && ($ft_t != '')){$ft_args['fttype'] = $ft_t;}
    if (isset($ft_p) && ($ft_p != '')){$ft_args['ftperiod'] = $ft_p;}
    if (isset($ft_d) && ($ft_d != '')){$ft_args['ftduration'] = $ft_d;}

and to make it work before version 3.1 you will need to install Query Multiple Taxonomies.

Hope this helps.

  • Thanks for this, much appreciated and I see that it's clearer and neater to put all the $ft_args into an array like that. However, I've done as you suggested and installed that plugin, but when I try to search, I reach a 404 page. Not sure what I can do to diagnose the problem - do you know why that might be happening? – Osu Feb 19 '11 at 16:32
  • hard to tell with no hand's on debugging but is you can "pastie" the code you use and the query_vard dump it would help. – Bainternet Feb 19 '11 at 16:37
  • @בניית אתרים - Please see my edit in the post above – Osu Feb 20 '11 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.