When I enable the admin search option, I stop having results in my P2P_box where you can search for posts.
See https://www.ads-software.com/extend/plugins/posts-to-posts/ for details on this plugin by Scribu.
I did some debugging and boiled it down to some problems i seem to be having with regards to the ‘the_posts’ filter and its checks on whether or not its an searchable query.
This is my current (crappy)work-around which seems to at least fix this problem, but could cause other problems instead (haven’t checked yet)
init.php line 4:
add_filter(‘the_posts’, ‘relevanssi_query’, 9, 2);
search.php line 36:
if ( $query->is_search ) {
$wp_query = apply_filters(‘relevanssi_modify_wp_query’, $query);
$posts = relevanssi_do_query($wp_query);
}
elseif ($search_ok) {
$wp_query = apply_filters(‘relevanssi_modify_wp_query’, $wp_query);
$posts = relevanssi_do_query($wp_query);
}
Please let me know if you get similar results when combining the P2P plugin and Relevanssi and enabling the admin search option.
Yst?v?llisin terveisin,
Ruud
https://www.ads-software.com/extend/plugins/relevanssi/
]]>Anyway, when WordPress query for posts, for example on the home page or the search page, it seems like the posts are 1st fetched, truncated to 10 (for example) results, and then, filtered, so, if there’s no post allowed on these 10, no post is shown.
The desired behavior is, obviously, remove ALL the disallowed posts first and then select 10 results.
A filter on the_posts does the first case, what will be the workflow for the second?
Thanks for all
]]>the function relevanssi_query()
is launched when the filter the_posts
is fired. This function retrieves the posts we are looking for, but, the WP_Query has already been launched and results analysed in &get_posts()
by WordPress.
Is it possible to add the following filter on pre_get_posts
:
add_filter('pre_get_posts', 'cancel_wp_query', 10, 1);
function cancel_wp_query($q) {
if( $q->is_search ) {
$q->query_vars['p'] = -1;
}
}
We specify to the query to find no post to optimize the loading time. Is it a bad idea ?
Thank you
]]>But, what I’m finding is that pagination is set when the list of posts is first built, and is not re-calculated after I delete any relevant posts.
As such, each page has a varying number of posts displayed, depending on how many I delete for that user.
Does anyone know how to re-paginate AFTER I run the the_posts filter?
Many thanks in advance,
Andy
I want to set up a the_posts hook to display adsense ads without having to modify templates.. It works, but how do I make sure that it will only add a post on the beginning of multiple posts, not a single (on single, i want to use a the_content hook) and also not to add a post in administration?
Thx.
]]>However if you just try this very short code:
//add_filter(‘the_posts’, ‘posts_pages_list’);
add_filter(‘get_pages’, ‘posts_pages_list’);
function posts_pages_list($posts) {
if (!empty($posts))
unset($posts[0]);
return $posts;
}
you have two broken behaviors depending on which line you uncomment:
1) with only the_posts filter you have a loop in manage pages that continue to draw pages and you have also two sql errors:
SELECT post_id, category_id FROM wp_post2cat WHERE post_id IN (,8,7,9,10,11,12)
SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN(,8,7,9,10,11,12) ORDER BY post_id, meta_key
you have two very similar sql errors also in manage posts
2) with only get_pages filter the site shows only a blank page and trying to print_r the array you can see that is magically truncated in the middle!!!
What’s wrong??? Bug?
Help me please
thanx
Marco
As far as I can tell, the the_posts
filter receives as its argument an array containing the posts returned for display by the query. My WordPress plugin, Comment Timeout, uses this filter to close comments on old posts.
However I have had a small number of users reporting an error message that indicates that something other than an array is being passed to this filter.
Under what circumstances is this likely to happen, if any? Should I suspect an incompatibility with another misbehaving plugin or am I overlooking something?
]]><?php
/*
Plugin Comments removed for posting on www.ads-software.com
*/
$my_cat = “1”;
function applysubbyposts($the_posts) {
global $wpdb;
if(!is_user_logged_in()) {
foreach($the_posts as $key => $post) {
$thiscat = $wpdb->get_var(“SELECT category_id FROM post2cat WHERE post_id=’$post->ID'”);
if(floatval($thiscat) == floatval($my_cat)) unset($the_posts[$key]);
}
}
return $the_posts;
}
add_filter(“the_posts”, “applysubbyposts”);
?>
That being said I have looked on the web site and know it has to do with ‘the loop” bur after an hour of waiting for the nausiatingly slow website to show the knowledge base I decided to come to you guys for help.
]]>