Forums

Relevanssi - A Better Search
global post not set (4 posts)

  1. brbrbr
    Member
    Posted 4 months ago #

    I have a situation where the global $post is not set.

    relevanssi_index_doc fals back in using the $indexpost set by the save_post hook.

    this value appear to be a integer, the post id, however the function checks $indepost with is_object.

    if (!isset($post)) {
                    $post_was_null = true;
                    if (is_object($indexpost)) {
                            $post = $indexpost;
                    }
            }

    shouldn't this be a isset or is_int? There is a is_object to get the right post_id a few lines further down.

    just curious: is there a reason to use the global $post as default instead of the post_id passed by the hooks? My two cents would be that the latter is the 'better' one.

    (and thanks for the great plugin btw)

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

  2. msaari
    Member
    Posted 4 months ago #

    No. The problem is that in some cases, the function gets a post object and in other cases it's a post ID and in some other situations it's an array.

    So, first it checks if it's an array. Then if it's an object, take it, otherwise fetch the object by the post ID.

    Later we refetch the post, because if it's done in any other way, the code fails in some situations. Don't ask me why, I don't really understand it myself. I just know that these all methods are necessary to cover all possible situations this function is called in.

    Also, in some cases the global $post object has the correct post ID, while the passed post ID is wrong (the post ID of the revision, not the original post).

    It's complicated =)

  3. brbrbr
    Member
    Posted 4 months ago #

    complicated? Sounds more like a mess :) My plugin uses wp_insert/update_post so would expect the parameters passed to the hook to be the correct one.

    the check on the passed parameter is now only on is_object. not on array/int.

    well, patching the is_object to is_int works for me, I just have to remember it on updates.

  4. msaari
    Member
    Posted 4 months ago #

    Using the quick edit on the Posts screen passes an array, for example.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags