antonozolin
フォーラムへの返信
-
フォーラム: 使い方全般
返信が含まれるトピック: query_postsで複数条件の指定Hello, friends. I have tried to use one of codes from your discussing, and I have a problem with it.
I do not understand, does this code should work correct?
function my_query_posts($q=''){ add_filter('posts_where', 'my_posts_where'); add_filter('posts_join', 'my_posts_join'); query_posts($q); remove_filter('posts_where', 'my_posts_where'); remove_filter('posts_join', 'my_posts_join'); } function my_posts_where($where){ global $wpdb; return $where . " AND $wpdb->postmeta.meta_key = 'test1' AND $wpdb->postmeta.meta_value = 'value1' AND $wpdb->postmeta.meta_key = 'test2' AND $wpdb->postmeta.meta_value = 'value2' AND $wpdb->postmeta.meta_key = 'test3' AND $wpdb->postmeta.meta_value = 'value3' "; } function my_posts_join($join){ global $wpdb; return $join . " JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) "; }I am asking, because it does not show anything, dispite of I have a post with theese fields and values.
but I want to add, that filter
function my_posts_where($where){ global $wpdb; return $where . " AND $wpdb->postmeta.meta_key = 'test1' AND $wpdb->postmeta.meta_value = 'value1' "; }Works fine. Please, can you wright me (in english) – did you solve this problem, and right the correct code. 感謝 =)
フォーラム: 使い方全般
返信が含まれるトピック: query_postsで複数条件の指定I think I got it. Thank you, will try soon.
フォーラム: 使い方全般
返信が含まれるトピック: query_postsで複数条件の指定Now my code is like this, works fine, but not quate accurate, I need to compare 2 meta_keys
function filter_where($where = '') { $date_start = ('30.03.2010'); $date_end = ('30.04.2012'); $where .= ' AND STR_TO_DATE(meta_value,"%d.%m.%Y") >= STR_TO_DATE("'.$date_start.'","%d.%m.%Y") AND STR_TO_DATE(meta_value,"%d.%m.%Y") <= STR_TO_DATE("'.$date_end.'","%d.%m.%Y") '; return $where; } function date_order($orderby = '') { $order .= 'STR_TO_DATE(meta_value,"%d.%m.%Y") ASC'; return $order; } add_filter('posts_where', 'filter_where'); add_filter('posts_orderby', 'date_order'); $args = array( 'category__and' => array($child_cat_id,$child_cat_id), 'meta_key' => $meta_field_name, 'showposts' => -1, ); $my_query = new WP_Query($args); remove_filter('posts_where', 'filter_where'); remove_filter('posts_orderby', 'date_order');Just in case =)
フォーラム: 使い方全般
返信が含まれるトピック: query_postsで複数条件の指定Hello. I am from Russia, so I am righting in English.
I have a problem like this, which is not discussing in my country.My problem is that I need to compare 2 meta_keys in function
filter_where($where = '') {}for$my_query = new WP_QueryAs I understood it is exactly what you are talking about.
As I understood with help of Google Translate, that you have solved this problem,But when I tried to do the same, nothing showed UP, I think I have mistaken in parts of code.
Because it is difficult to understand what to copy.
Could you please write the whole code, where in query will be post with
meta_key = "test1" meta_value = "1" meta_key = "test2" meta_value = "2"and from 1 specific category CAT1_id.
Thank you for helping, hope for your answer. =)