因此,我在So上偶然发现了许多类似的问题,但我对wp\\U query和高级PHP的理解有限。我想我在PHP对象/数组和get_the_
和the_
功能。代码在(根主题等效)功能中。php。
我正在使用var_dump
还有ChromePhp,但当我尝试这样做时,我的页面经常会崩溃或冻结。
function tags()
{
// If current post has tags
if (get_the_tags())
{
$post_id = get_the_id();
$posttags = get_the_tags();
// Loop for each tag the custom post has
foreach($posttags as $tag)
{
$tag_name = ($tag->slug);
// Search for posts with the same tag,
// is a custom type and don\'t return
// the current post
$args = array(
\'post_type\' => \'custom_post\',
\'tag\' => $tag_name,
\'post__not_in\' => array( $post_id )
);
$query = new WP_Query( $args );
// Make sure we got results
if( $query->have_posts() )
{
// Loop through each returned post
while ( $query->have_posts() )
{
$query->the_post(); // Returns null
...other things generally lock up the page...
$example = ($query->posts[0]); // Crashes the server
}
}
wp_reset_postdata();
}
}
}
add_shortcode(\'shortcodetag\', \'tags\');
因此,这似乎在某种程度上是可行的,我可以根据当前标记返回正确的帖子。问题只是访问这些返回帖子中的信息。最后的while循环只是将页面研磨到停止状态30秒,然后我出现服务器错误。