从未遇到过这样的事情。运行自定义帖子类型的简单查询,只显示当前用户是作者的帖子类型,并按自定义元字段对其进行排序。
global $current_user;
$user = wp_get_current_user();
$args = array(
\'post_type\' => \'order\',
\'post_status\' => \'publish\',
\'author\' => $current_user->ID,
\'posts_per_page\' => \'-1\',
\'meta_query\' => array(
array(
\'key\' => \'completed\',
\'value\' => \'\'
)
),
);
$query = new WP_Query( $args );
这将返回结果。当我加载项时
\'order\' => \'ASC\',
查询不返回任何结果。对我来说完全没有意义。
仅供参考,以下是整个部分。
// ========== ORDERS QUERY CODE ==========
$orders = \'\';
global $current_user;
$user = wp_get_current_user();
$args = array(
\'post_type\' => \'order\',
\'post_status\' => \'publish\',
\'author\' => $current_user->ID,
\'posts_per_page\' => \'-1\',
\'meta_query\' => array(
array(
\'key\' => \'completed\',
\'value\' => \'\'
)
),
\'meta_key\' => \'delivery_date\',
\'order\' => \'ASC\',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$thePostID = get_the_ID();
$shortDesc = wordwrap(substr(get_the_content(), 0, 100), 99, \'...\');
$quantity = get_post_meta( $thePostID, \'order_quantity\', true );
$orders .= \'<div class="order-single order-\'.$thePostID.\'">
<div class="row">
<div class="col-4">
<div class="single-cal">
<div class="month">\'.date_i18n(\'F\', strtotime(get_post_meta( $thePostID, \'delivery_date\', true ))).\'</div>
<div class="day">\'.date_i18n(\'j\', strtotime(get_post_meta( $thePostID, \'delivery_date\', true ))).\'</div>
</div>
</div>
<div class="col-8">
<a class="order-customer" href="\'.get_the_permalink().\'">
\'.get_the_title().\'
</a>
<div class="order-desc">
<div class="qty"><strong>Quantity:</strong> \'.$quantity.\'</div>
\'.$shortDesc.\'
</div>
</div>
</div>
</div>\';
}
} else {
$orders .= \'No Orders Found. <a href="/add">Click Here</a> to enter your first Order!\';
}
wp_reset_postdata();
更新01:已安装插件。不知道如何使用它,但看起来这是该调用的SQL。
SELECT wp_y77uhd4169_posts.*
FROM wp_y77uhd4169_posts
INNER JOIN wp_y77uhd4169_postmeta
ON ( wp_y77uhd4169_posts.ID = wp_y77uhd4169_postmeta.post_id )
INNER JOIN wp_y77uhd4169_postmeta AS mt1
ON ( wp_y77uhd4169_posts.ID = mt1.post_id )
WHERE 1=1
AND wp_y77uhd4169_posts.post_name = \'asc\'
AND wp_y77uhd4169_posts.post_author IN (1)
AND ( wp_y77uhd4169_postmeta.meta_key = \'delivery_date\'
AND ( ( mt1.meta_key = \'completed\'
AND mt1.meta_value = \'\' ) ) )
AND wp_y77uhd4169_posts.post_type = \'order\'
AND ((wp_y77uhd4169_posts.post_status = \'publish\'))
GROUP BY wp_y77uhd4169_posts.ID
ORDER BY wp_y77uhd4169_posts.post_date ASC