WordPress.org

Support

Support » Plugins and Hacks » Relevanssi - A Better Search » [Resolved] $sitepress->is_translated_post_type on a non-object

[Resolved] $sitepress->is_translated_post_type on a non-object

  • Hello,

    I am not certain why a few of our posts have no post_type data, but in common.php line 15, you have the code:
    if (function_exists('icl_object_id') && $sitepress->is_translated_post_type($hit->post_type)) {

    I receive an error here. Can we change it to:
    if (function_exists('icl_object_id') && isset($hit->post_type) && $sitepress->is_translated_post_type($hit->post_type)) {

    Thank you.

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

Viewing 15 replies - 1 through 15 (of 18 total)
  • Sorry, this was the log entry:
    [Fri Jan 17 11:20:38 2014] [error] [client 194.232.128.225] PHP Fatal error: Call to a member function is_translated_post_type() on a non-object in /app/www/cms3.ots.at/htdocs/wp-content/plugins/relevanssi/lib/common.php on line 15

    I checked for the string: global $sitepress;

    A couple other plugins use this variable too in their code, but wordpress core 3.8 and the other installed plugins that we have do not declare it or set it.

    Where was $sitepress originally declared.

    Plugin Author Mikko Saari

    @msaari

    That particular code is for the WPML compatibility. If you’re not using WPML (and hence $sitepress is not set), why is the WPML compatibility feature enabled?

    Polylang is active as a plug-in.

    Plugin Author Mikko Saari

    @msaari

    Change the if clause to this:

    if (function_exists('icl_object_id') && !function_exists('pll_is_translated_post_type')) && $sitepress->is_translated_post_type($hit->post_type)) {

    Does that remove the error?

    Other than one too many ‘)’s in the above change, the suggestion appears to work properly. If I do not post anything further, our team was able to verify that the changes worked properly.

    Thanks Mikko for the support. I was not certain if we needed to be in the “else” portion of the conditional or not.

    Here’s the patch if it helps:

    Index: lib/common.php
    ===================================================================
    --- lib/common.php	(revision 1)
    +++ lib/common.php	(working copy)
    @@ -12,7 +12,7 @@
     				switch_to_blog($hit->blog_id);
     			}
     			global $sitepress;
    -			if (function_exists('icl_object_id') && $sitepress->is_translated_post_type($hit->post_type)) {
    +			if (function_exists('icl_object_id') && !function_exists('pll_is_translated_post_type') && $sitepress->is_translated_post_type($hit->post_type)) {
     			    if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE))
     			        $filtered_hits[] = $hit;
     			}
    Plugin Author Mikko Saari

    @msaari

    Polylang users should end up in the “else” part, yes. Thanks, if I don’t hear anything else from you, I’ll add this fix to the next version.

    Thanks for this temporary solution! Using Relevanssi with polylang and this fixed the issue 🙂

    After 1 week of using this patch on a production installation there are no issues that have come up. Please commit, thanks.

    Hi!

    I’ve found an issue with this combined with post_type specific searches.. When using a custom searchform with
    <input type="hidden" name="post_type" value="mycpt" />
    and having the WPML/Polylang box ticked in relevanssi settings it does not retrieve any results at all. I’ve double/tripple checked everything and all my code is solid and I’m searching for thing that’s definitely there and should be in the index.

    When unchecking the setting the posts do show up. So could there be a clash between this and the checking for a “post_type” parameter?

    Plugin Author Mikko Saari

    @msaari

    Is that a translated post type? Looks like if the post type is not a translated post type, it gets removed from the results in every case.

    Does this version of the function work better? http://pastebin.com/HireiPEn

    It was not a translated post type but I made it one now (forgot it).

    I forgot to mention that I’m using polylang (says so in my earlier comment)..
    Tried your new function and it does not help.. Here’s what I’ve done:

    1. Set posttype to be translatable in polylang settings
    2. Set all “unhooked” posts to the default language (function in polylang)
    3. Manually updated atleast one post which I use for testing the search (to make absolute sure it’s been set to default language)
    4. Rebuilt index in relevanssi
    5. tried searching for said post.

    It still does not retrieve any results tho =/
    Could it be because I’m using polylang rather than WPML. Seems your changes is only for WPML, correct?

    The patch I applied was for polylang users, not WPML. This is not your issue.

    Can you recheck your website default language? Is that set to the same language you are looking for I am using a multi-site set-up so it is in my Administration settings page.

    Aye I know it’s not exactly the same as your issue but I figured it was closely related enough to allow for me to continue on this thread.

    If not, do tell. I will create a separate support post 🙂

    I’m certain my default language is set up correctly and that the posts I’m searching for is attached to this language (in my case swedish). Checked and rechecked the language settings page. I do not use WPMU so the settings are found in settings>language

    Plugin Author Mikko Saari

    @msaari

    I’d take a closer look at how posts behave in the filter function. Do the missing posts enter the function (obviously they don’t exit it)? If they do, where do they disappear, and how would you change the function to make them not disappear?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Resolved] $sitepress->is_translated_post_type on a non-object’ is closed to new replies.
Skip to toolbar