我正在尝试显示 CPT 内容以进行存档和带有钩子的单个页面(自定义内容功能)。我可以部分显示内容,但要么显示双重(循环)内容,要么抛出一些对象字符串错误。
下面是我在cpt single中使用的2种方法。
if ( ! function_exists( 'portfolio_single_content' ) ) {
function portfolio_single_content( $content ) {
global $post;
if ($post->post_type == 'zpt_portfolio') {
$content .= the_title($post->ID);
}
return $content;
}
}
add_filter('the_post','portfolio_single_content');
这将返回以下错误;
214测试产品组合
可恢复的致命错误:无法将215行的/var/www/html/wordpress/wp-content/plugins/zpt-portfolio/zpt-portfolio.php中的WP_Post类的对象转换为字符串
开发说明:第215行是 $ content。= the_title($ post-> ID);
function new_default_content($content) {
global $post;
if ($post->post_type == 'zpt_portfolio') {
$content .= the_post_thumbnail('thumb');
$content .= '<h2>' . get_the_title() . '</h2>';
$content .= get_the_content();
}
return $content;
}
add_filter('the_content', 'new_default_content');
这将两次返回帖子内容。请参阅随附的屏幕截图作为参考。
Method 2 notification screenshot
我已经尝试过使用CPT存档进行同样的操作,但是除了通常的循环内容之外,没有显示在那里。
任何建议将不胜感激。感谢您审核我的查询并提前帮助我。