$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Loop (for search results) returning right posts, but wrong post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Loop (for search results) returning right posts, but wrong post type

matteradmin7PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far