query posts by custom field value by clicking on a link?
-
I am modifying an existing theme. It has events listing functionality using a post category (not custom post type). Originally it was just listing all of the events, but it needed to show upcoming events (so people see the next event first). I got this to work perfectly by adding the following query to the template events.php:
‘$is_events_child = cat_is_ancestor_of($_reserved_categories[‘events’], get_query_var(‘cat’));if( is_category(‘events’))
{query_posts($query_string . ‘&meta_key=fw_event_time&meta_value=’.time().’&meta_compare=>&orderby=meta_value&order=ASC’);
}
if($is_events_child)
{query_posts($query_string . ‘&meta_key=fw_event_time&meta_value=’.time().’&meta_compare=>&orderby=meta_value&order=ASC’);
} /*there’s prob a better way to do this but this worked to include events sub-categories*/’I want to add a link at the top that says “View past events”. I think the simplest way to do this is to run a new query and change meta_compare to =< . So I added this:
‘“>View past events$past_events = query_posts($query_string . ‘&meta_key=fw_event_time&meta_value=’.time().’&meta_compare=<&orderby=meta_value&order=ASC’);’
This doesn’t work – any suggestions? I am fairly new to php so I’m probably doing something stupid…
- The topic ‘query posts by custom field value by clicking on a link?’ is closed to new replies.