Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function recipes_get_posts($category)
- {
- $args = array(
- 'numberposts' => 5, //Add all or pagination later
- 'orderby' => 'DESC', //Custom sort later?
- 'post_type' => 'recipes',
- 'recipes_category' => $category,
- 'post_status' => 'publish',
- 'tax_query' => array(
- 'relation' => 'AND', // can be OR too
- array(
- 'taxonomy' => 'rating',
- 'field' => 'slug', // you can use ID too
- 'terms' => get_query_var('your_var_from_form') // you can pass an array with terms or ID's too
- ),
- array(
- 'taxonomy' => 'calorie-range',
- 'field' => 'id',
- 'terms' => array( 103, 115, 206)
- )
- ) // end tax query array
- ); // end args
- $posts = get_posts($args);
- // posts into an array
- $arr = array();
- foreach ($posts as $post) {
- $listing = array();
- // Customize content in array later, ID/Title for testing purposes
- $listing['id'] = $post->ID;
- $listing['title'] = $post->post_title;
- $arr[] = $listing;
- }
- header("Content-Type: application/json");
- json_encode($arr);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement