Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. query_posts(array(
  2. array('post'), 'tax_query' => array(array( 'taxonomy' => 'post_format',
  3. 'field' => 'slug',
  4. 'terms' => array('post-format-image'))),
  5. 'cat' => '-173',
  6. 'post_status' => 'publish')
  7. );'
  8.  
  9. // This takes your current query, that will have the filtering part added to.
  10. $query_string = array(
  11. 'post_type' => 'post',
  12. 'tax_query' => array(array( 'taxonomy' => 'post_format',
  13. 'field' => 'slug',
  14. 'terms' => array('post-format-image'))),
  15. 'cat' => '-173',
  16. 'post_status' => 'publish');
  17.  
  18. // Create a new filtering function that will add our where clause to the query
  19. function filter_where( $where = '' ) {
  20. // posts in the last 30 days
  21. $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
  22. return $where;
  23. }
  24.  
  25. add_filter( 'posts_where', 'filter_where' );
  26. $query = new WP_Query( $query_string );
  27. remove_filter( 'posts_where', 'filter_where' );
  28.  
  29. function wpse52070_filter_where( $where = '' , $query) {
  30. if( $query->is_main_query() && is_page( 'foobar' ) ){
  31. // posts in the last 30 days
  32. $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
  33. }
  34.  
  35. return $where;
  36. }
  37.  
  38. add_filter( 'posts_where', 'wpse52070_filter_where' );
  39.  
  40. $query_string = array(
  41. 'post_type' => 'post',
  42. 'date_query' => array(
  43. 'after' => '2012-04-01'
  44. ),
  45. 'tax_query' => array(array( 'taxonomy' => 'post_format',
  46. 'field' => 'slug',
  47. 'terms' => array('post-format-image'))),
  48. 'cat' => '-173',
  49. 'post_status' => 'publish');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement