Created
September 24, 2013 11:51
-
-
Save ivankravchenko/6683621 to your computer and use it in GitHub Desktop.
Wordpress JSON-API support for Sencha Ext.Store filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Wordpress JSON-API support for Sencha Ext.Store filters | |
// https://gist.github.com/krava/6683621 | |
add_action('json_api-core-get_recent_posts', 'wapp_customize_get_recent_posts'); | |
function wapp_customize_get_recent_posts() { | |
// filter: [{"property":"category","value":"1"},...] -> cat=:id, ... | |
global $wp_query; | |
if (isset($_GET['filter'])) { | |
$filter = json_decode(stripslashes($_GET['filter'])); | |
foreach ($filter as $singleFilter) { | |
$property = $singleFilter->property; | |
$value = $singleFilter->value; | |
switch ($property) { | |
case 'category': | |
$wp_query->query['cat'] = $value; | |
break; | |
case 'fromDate': | |
$wp_query->query['date_from'] = $value; | |
break; | |
case 'toDate': | |
$wp_query->query['date_to'] = $value; | |
break; | |
default: | |
die("Unknown filter: $property"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment