pre_get_posts problem
-
Hi, I made a plugin to allow non-logged visitors to posts from the frontend.
It uses a specific user as “guest account”.
When a guest post something, a meta_key “oqp_gkey” is saved with the post; containing this visitor email (which he filled with the form).Now; when I display the posts by author (eg. author/guest); it lists all posts by the “guest” account, not only the posts by this particular guest.
So I added a parameter to the author URL (eg. author/guest/?oqp_gkey=CRYPTED_EMAIL) which should retrieve the posts written only by this “email”.
For this, I use pre_get_posts.
But even if it seems that my query IS set with the values I want; the posts returned do not match the meta_key; it returns all posts by the “guest” account.
Any idea ?Here’s the code :
add_filter('pre_get_posts',array(&$this,'filter_query')); function filter_query(&$query) { if ($query->query_vars['suppress_filters']) return $query; print_r("add guest query filter"); //DO PRINT $dummy = $this->dummy; //GET DUMMY USER $wp_author = $query->get('author_name'); //QUERY IS FILTERED BY AUTHOR NAME $wp_author_ID = $query->get('author'); //QUERY IS FILTERED BY AUTHOUR ID if (($wp_author !=$dummy->user_nicename) && (!oqp_user_is_dummy($wp_author_ID)))return false; //author is not the dummy user if ($wp_author==$dummy->user_nicename) { $dummy_email=$query->get('oqp_gkey'); $dummy_email = oqp_simple_decode($dummy_email,'oqp-dummy-email'); //DECRYPT EMAIL }elseif((oqp_user_is_dummy($wp_author_ID)) && ($post)) { $dummy_email = get_post_meta($post->ID,'oqp_guest_email', true); } if (!$dummy_email) return false; //no key to analyze print_r("do guest query filter: ".$dummy_email); //DO PRINT //get all ads for this email, //not only for this guest $query->set('author_name',false); $query->set('author',false); $query->set('meta_key','oqp_guest_email'); $query->set('meta_value',$dummy_email); add_action('oqp_after_the_loop',array(&$this,'remove_query_filter')); return $query; }
- The topic ‘pre_get_posts problem’ is closed to new replies.