尝试以下操作:
<?php
$args = array(
\'post_type\' => \'product\',
\'post_status\' => \'publish\',
\'meta_key\' => \'views\',
\'orderby\' => \'meta_value_num\',
\'order\'=> \'DESC\', // sort descending
);
// Custom query.
$query = new WP_Query( $args );
// Check that we have query results.
if ( $query->have_posts() ) {
// Start looping over the query results.
while ( $query->have_posts() ) {
$query->the_post();
$comma_char = ($query->current_post + 1) < ($query->post_count) ? "," : "";//add comma if not last post
printf(\'<a href="%s" class="link">%s</a>\' . $comma_char, get_permalink(), get_the_title());
}
}
// Restore original post data.
wp_reset_postdata();
?>
至于第二个问题(顺便说一句,这是帖子的第一个问题),看起来像是一个标准的WordPress查询,如果不知道它的细节,很难说它可以如何改进。