Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Mikko Saari

    (@msaari)

    add_filter('relevanssi_valid_status', 'only_publish');
    function only_publish($array) { return array('publish'); }
    Thread Starter oldalgazda

    (@oldalgazda)

    Hi Mikko,

    Thank you for your prompt answer – awesome plugin with avesome support!
    I am sorry to ask you one question more. What could be the reason if having inserted the above code snippet in functions.php it still displays private posts among the search results?

    Thank you again,
    József

    Plugin Author Mikko Saari

    (@msaari)

    You also need to reindex the database, because just adding the code does not remove anything from the index. Once you reindex, there should only be published posts left in the database.

    Thread Starter oldalgazda

    (@oldalgazda)

    Terve Mikko,

    Thank you, I dindn’t know that this filter thing happens on the indexing level not on the query level, so I could never ever figure this out without your help.

    Thanks again,
    József

    Thanks for the tip in this post, I have a custom post type that uses a custom status of “expired” that I want indexed, so I used:

    add_filter(‘relevanssi_valid_status’, ‘only_publish’);
    function only_publish($array) { return array(‘publish’,’expired’); }

    I do see that the correct number of posts are being indexed, however when I actually execute a search on the website none of the posts with the custom status “expired” are displaying. Do I need to modify the main WordPress search query too in order to get this to work?

    Thanks for the great plugin.

    Plugin Author Mikko Saari

    (@msaari)

    By default, Relevanssi only shows posts with status “publish”, and “private” posts where the searcher has a permission to see them.

    So, what you need to do is to add another filter on relevanssi_post_ok:

    add_filter('relevanssi_post_ok', 'ok_the_expired', 11);
    function ok_the_expired($post_ok, $doc) {
        $status = relevanssi_get_post_status($doc);
        if ('expired' == $status) $post_ok = true;
        return $post_ok;
    }

    (Admin search shows everything, but I noticed it doesn’t care about valid_status filter as it should; I’ll fix that.)

    Very cool, thank you. I pasted the hook you suggested above, it looks like exactly what I need, but unfortunately it’s not working. The only way I can manage to get it to work is to change lib/common.php:

    if ('publish' != $status ) {
    		$post_ok = false;
    	}

    to

    if ('publish' != $status && 'expired' !=$status ) {
    		$post_ok = false;
    	}

    Seems like this is the same thing as the filter hook, any idea why it wouldn’t be working? Thanks again for the assistance.

    Plugin Author Mikko Saari

    (@msaari)

    That logic is going to fail, because if $status is ‘expired’, the ‘publish’ != $status check fails and the second part of the AND clause is not even looked at.

    if (!in_array($status, array('publish', 'expire')) {

    should work better.

    I’m not sure why the code I gave you doesn’t work, but I know the custom post status part of WordPress isn’t quite finished yet – I’m using custom post statuses on one of my sites, and there are some issues with them. Perhaps this is related.

    hursey013

    (@hursey013)

    Thank you for the pointer – I don’t think I fully thought out the code I posted, yours makes much more sense and gets things working right. I’ll keep trying the filter method to see if I can get it to work, still don’t understand why it doesn’t. Thanks a bunch, keep up the good work!

    hursey013

    (@hursey013)

    Just checked out my error logs and for the snippet you provided earlier:

    add_filter('relevanssi_post_ok', 'ok_the_expired', 11);
    function ok_the_expired($post_ok, $doc) {
        $status = relevanssi_get_post_status($doc);
        if ('expired' == $status) $post_ok = true;
        return $post_ok;
    }

    I’m getting the following error, which could explain why it wasn’t working:

    [09-Feb-2014 05:56:37 UTC] PHP Warning: Missing argument 2 for ok_the_expired() in /public_html/wordpress/wp-content/themes/jobify-child/functions.php on line 127

    Any suggestions on how to fix that? Thank you!

    Plugin Author Mikko Saari

    (@msaari)

    add_filter('relevanssi_post_ok', 'ok_the_expired', 11);

    should be

    add_filter('relevanssi_post_ok', 'ok_the_expired', 11, 2);

    so the second parameter gets passed to the function. My mistake, sorry.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to use relevanssi_valid_status filter’ is closed to new replies.