Yes, you can fix this. By default, Relevanssi only indexes the following post statuses: publish, private, draft, pending, and future.
If you want to add a status to that list, you need to add this to your theme functions.php:
add_filter('relevanssi_valid_status', 'rlv_add_status');
function rlv_add_status($status_array) {
$status_array[] = "sold";
return $status_array;
}
Then reindex.
Thread Starter
walpap
(@walpap)
Mikko, you are awesome! You give a great support even to free users.
Thank you so much. Really.
I forgot to mention that the “sold” products are with 0 stock, so they dont appear in the front end. I just want to search them in the admin section.
So.. the code you sent me didnt work at first..
I added it to the functions.php of my theme, then reindexed relevanssi.
I realized the number of indexed posts grew up, so it did something..
But then i wanted to search one product with the “sold” status, and it still didnt found it. I think you missed something there.
So i went to Relevanssi plugin files, and found this line in common.php
// only show drafts, pending and future posts in admin search
if (in_array($status, array('draft', 'pending', 'future')) && is_admin()) {
$post_ok = true;
}
So i added ‘sold’ after future, and then it worked.
Im happy with that, but i would like not to touch the plugin files.
So i ask you if what i did was ok and if you can correct the code you wrote before, so i can use only functions.php.
Take care!
Hmm, that is hardcoded, and cannot be changed by a filter. Let’s add a filter there, then. Change the code to this:
// only show drafts, pending and future posts in admin search
if (in_array($status, apply_filters('relevanssi_valid_admin_status', array('draft', 'pending', 'future'))) && is_admin()) {
$post_ok = true;
}
Then add this to your theme functions.php:
add_filter('relevanssi_valid_admin_status', 'rlv_add_status');
Now it should work and be update proof as well, I’ll include the filter in the next version.
Thread Starter
walpap
(@walpap)
Mikko, when you say:
“Then add this to your theme functions.php:
add_filter(‘relevanssi_valid_admin_status’, ‘rlv_add_status’);”
You mean to add it like this, right?
add_filter('relevanssi_valid_admin_status', 'rlv_add_status');"
function rlv_add_status($status_array) {
$status_array[] = "sold";
return $status_array;
}
Because, if i dont add the function after, it does not work.
I assumed you had the function already, because you need the other filter hook as well, like this:
add_filter('relevanssi_valid_status', 'rlv_add_status');
add_filter('relevanssi_valid_admin_status', 'rlv_add_status');
function rlv_add_status($status_array) {
$status_array[] = "sold";
return $status_array;
}
Thread Starter
walpap
(@walpap)
Thank you very much Mikko!
Take care.