0

Hoping this isn't already asked/answered, but it's a tough one to search. I've got a site based on the Flatsome theme which uses custom post types (through various plugins). The search page works in that it returns the right pages/posts/users (using Relevanssi).

However, in content.php within our child theme, we have custom code that displays special content in results for users (members). This code works for most users, but for some the post type seen is either "blocks" or product_variation (we're using WooCommerce). This snippet is slightly modified to simply output what we're seeing in the search results for the problem records; all I'm doing, really, is using get_posts() to load up info about the page/post/user so I can display the object appropriately:

$post_info = get_post(get_the_ID());
$user_id = ($post_info->post_type == 'user') ? $post_info->user_id : $post_info->ID;
echo "Record is a " . $post_info->post_type . " with ID " . $user_id . "<br />";

This displays the following before the search result that is a user:

Record is a blocks with ID 542

I've worked around this by treating these users as users if their post_type is user, blocks, or product_variation; but something must be amiss.

I debugged this by putting extra code in the Relevanssi plugin to output the search results (the return from relevanssi_do_query()). The problem record I've been focusing on looks completely fine there, set to "user". But when I output the post type within content.php (retrieved via get_post()), it displays as blocks. Happy to debug this further, but I've not yet had to debug the WP core this deeply before. Thanks for the help.

  • Could you please add the custom code in the question to be able to have a look in case there is something off in there. – Kumar Mar 18 '19 at 8:17
  • Added. I do wonder if the way the templates are set up with this theme, whether I should have this search result code within a template file somewhere else, and the system set up to utilize this more specific template file. content.php seems to me to be a more general, high-level template. – BertPC Mar 18 '19 at 19:08
  • I realize this question is probably tough to fully answer... but I'd appreciate any suggestion of how to troubleshoot "the loop" or otherwise check into how looping through posts would end up getting confused as to what type each post is. It almost seems like these extra custom post types aren't configured everywhere they need to be. ?? – BertPC Mar 18 '19 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.