WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] $sitepress->is_translated_post_type on a non-object (19 posts)

  1. jjchinquist
    Member
    Posted 7 months ago #

    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/

  2. jjchinquist
    Member
    Posted 7 months ago #

    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

  3. jjchinquist
    Member
    Posted 7 months ago #

    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.

  4. Mikko Saari
    Member
    Plugin Author

    Posted 7 months ago #

    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?

  5. jjchinquist
    Member
    Posted 7 months ago #

    Polylang is active as a plug-in.

  6. Mikko Saari
    Member
    Plugin Author

    Posted 7 months ago #

    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?

  7. jjchinquist
    Member
    Posted 7 months ago #

    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;
     			}
  8. Mikko Saari
    Member
    Plugin Author

    Posted 7 months ago #

    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.

  9. Jonathandejong
    Member
    Posted 7 months ago #

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

  10. jjchinquist
    Member
    Posted 7 months ago #

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

  11. Jonathandejong
    Member
    Posted 7 months ago #

    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?

  12. Mikko Saari
    Member
    Plugin Author

    Posted 7 months ago #

    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

  13. Jonathandejong
    Member
    Posted 7 months ago #

    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?

  14. jjchinquist
    Member
    Posted 7 months ago #

    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.

  15. Jonathandejong
    Member
    Posted 7 months ago #

    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

  16. Mikko Saari
    Member
    Plugin Author

    Posted 6 months ago #

    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?

  17. Jonathandejong
    Member
    Posted 6 months ago #

    So I've taken your advice and looked into the function.

    The issue is here:
    if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE)){
    on row 29.

    The function icl_object_id does not return the post id of the current post if the third parameter is set to false. This is because the post we're trying to find a translation for is the actual post we want and not a translation. Basically.. if I set the third parameter (return default post if no translation is found) OR create a translation in any language for the post it will return properly.

    So I suppose the solution would be to either simply change false to true (which might not be the desired outcome) or do some sort of check for each $hit language and if is current language ignore icl_object_id function.

  18. Jonathandejong
    Member
    Posted 6 months ago #

    UPDATE:

    I rewrote the function to check for current post language first and if not matching run the icl_object_id function so now it works properly with or without translation and does not require the third parameter to be true thus keeping the same functionality.

    http://pastebin.com/KtafvEqw

    Let me know if you want this submitted in some way?

  19. Mikko Saari
    Member
    Plugin Author

    Posted 6 months ago #

    Thanks, this is good, I'll make sure this gets included in the next version.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.