[英]Undefined variable on wordpress query
我遇到一个Undefined variable: warning
在我的Wordpress插件上Undefined variable: warning
。
我该如何解决? 以下是短代码中的查询摘要,而不是完整功能。 我正在遇到包含$ post_thumbnail的行。 谢谢。
function project_shortcode( $atts ) {
extract( shortcode_atts( array(
'limit' => '10',
'orderby' => 'date',
), $atts ) );
$output = '';
$loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => $limit, 'orderby' => $orderby));
// Looping through the posts and building the HTML structure.
if($loop){
$output .= '<ul id="og-grid" class="og-grid">';
while ($loop->have_posts()){
$loop->the_post();
//If has thumbnail
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
更新
行$post_thumbnail_id = get_post_thumbnail_id($post->ID);
您的问题是,您正在使用未定义的vars(警告告诉您。。)。 而且不仅是$post
var,还没有定义$limit
和$orderby
。
为了解决您的问题,您可以将所有缺少的vars作为参数传递给project_shortcode
并在函数调用中进行设置。
function project_shortcode($atts, $post, $orderby, $limit) //...
并且不要忘了通过变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.