WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
how to auto index posts from "front end"? (14 posts)

  1. 2046
    Member
    Posted 2 years ago #

    Hello,

    here is my case. Users on "my" website (http://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

    http://wordpress.org/extend/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. jebus
    Member
    Posted 2 years ago #

    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.

  4. 2046
    Member
    Posted 2 years ago #

    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. )

  5. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  6. scamp50
    Member
    Posted 2 years ago #

    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);

    .......

  7. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  8. scamp50
    Member
    Posted 2 years ago #

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

  9. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

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

  10. 2046
    Member
    Posted 2 years ago #

    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

  11. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  12. scamp50
    Member
    Posted 2 years ago #

    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

  13. Mikko Saari
    Member
    Plugin Author

    Posted 2 years ago #

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

  14. scamp50
    Member
    Posted 2 years ago #

    Thanks this all worked.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic