• Hello,

    here is my case. Users on “my” website (https://events.artycok.tv/) are able to add posts from front end only. But the Relevanssi doesn’t notice any of these new posts. If I want to have them indexed I should do it manually from plugin settings.

    My question is what kind of trigger should I use to have them indexed?

    I wrote the front end posting my self, so I’m free to make any required changes.
    I have the “Relevanssi Premium Version 1.7.3”

    thank you in advance 2046

    https://www.ads-software.com/extend/plugins/relevanssi/

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

    (@msaari)

    Relevanssi is attached to the save_post hook. So, make sure your code runs the actions on that hook, giving the post object as a parameter. At that point the post status must be publish, otherwise it won’t be indexed.

    I have a similar issue, in that I’m using a cron to create posts in a certain category. That’s using the wp_insert_post function to create the posts, but they aren’t being indexed by Relevanssi. Am I right in assuming that they should be indexed through the save_post hook, and so something else must be going on?

    Thanks for this great plugin, by the way. It really improves on the default WP search, which is less than ideal.

    Thread Starter 2046

    (@o-o)

    RE msaari:

    something like:

    // $pid is the id of the post
    $the_post_object = get_post($pid); // the post object
    do_action( 'save_post', $pid, $the_post_object );

    If that is what we need, then it doesn’t work for me.

    (I use the “wp_insert_post” as well. The “save_post” action is something extra I have added recently to test msaari’s suggestion.
    Frankly I’m not sure if these two actions running at the “same” time are not causing something nasty. )

    Plugin Author Mikko Saari

    (@msaari)

    wp_insert_post() calls save_post, so if you use that, Relevanssi should be able to index the posts.

    So, it’s something else, but what, I don’t know… You could try putting a mail() call or some other way of logging in relevanssi_edit() or relevanssi_index_doc() in order to see if the process reaches that far.

    I have the same issue on my website – so I took msaari advice and used the mail() call to try and see where the Index code was failing.

    The function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields = false) {

    was being called from where my posts were being saved – however the Post ID it pickup was always ID=20!!! I never changed.

    So I created another function, added it to my function file – it is the same as except for the top few lines – and I explicitly called it from my save post code…. – not sure if this will help anyone else but it solved the issue for me.

    function relevanssi_index_doc($indexpost, $remove_first = false, $custom_fields = false) {
    	global $wpdb, $relevanssi_table, $post;
    	$post_was_null = false;
    
    	if (is_array($post)) {
    		$post = $post['ID'];
    	}
    
    	if (!isset($post)) {
    		$post_was_null = true;
    		if (is_object($indexpost)) {
    			$post = $indexpost;
    		}
    	}
    
    	if ($post == NULL) return;
    	is_object($post) ? $ID = $post->ID : $ID = $post;
    	$post = get_post($ID);

    to

    function relevanssi_index_doc_byId($geo_post_id, $remove_first = false, $custom_fields = false) {
    	global $wpdb, $relevanssi_table, $post;
    	$post_was_null = false;
    
    	$post = get_post($geo_post_id);

    …….

    Plugin Author Mikko Saari

    (@msaari)

    I’m going to fix this problem in the next version: relevanssi_index_doc() will get a parameter that forces it to bypass the global $post, so it’s easier to make it index a particular $post->ID. That should make it easier to call directly.

    so will we be able to call it with an ID as well as a Post object?

    Plugin Author Mikko Saari

    (@msaari)

    Yes. It’ll accept either post ID, post object or post array as the first parameter.

    Thread Starter 2046

    (@o-o)

    I will appreciate if there will be some notes regarding this issue.
    All the Premium change logs etc. giving mostly no information what so ever.

    thanks 2046

    Plugin Author Mikko Saari

    (@msaari)

    So, this is now fixed in 2.9.13, available now.

    If you want a post indexed, call

    relevanssi_index_doc($id, $remove_first, $custom_fields, $bypasspost);

    where $id is either ID or the complete $post object for the post to index. If $remove_first is true, the post is first removed from the db, then indexed. $custom_fields should have a list of custom fields to index (get them from relevanssi_get_custom_fields(). Set $bypasspost to true to make the plugin bypass the global $post object.

    Let me know if this works for you.

    Brilliant – I will test this today. Just one thing – why would I or when would I:

    set $remove_first is true, the post is first removed from the db

    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    You use that when you’re updating the post, so the old version gets removed from the index before the new version is indexed.

    Thanks this all worked.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] how to auto index posts from "front end"?’ is closed to new replies.