0
我有一個名單與數百人,他們的全名(第一個最後)是在標題。有沒有一種方法來按字母順序查詢這些帖子,但使用標題中的姓氏(第二個詞)?wordpress查詢與標題姓氏
我發現這個http://ms-studio.net/tutorials/sorting-titles-by-last-name-in-wordpress/,但我無法理解怎麼會在WP查詢工作
我有一個名單與數百人,他們的全名(第一個最後)是在標題。有沒有一種方法來按字母順序查詢這些帖子,但使用標題中的姓氏(第二個詞)?wordpress查詢與標題姓氏
我發現這個http://ms-studio.net/tutorials/sorting-titles-by-last-name-in-wordpress/,但我無法理解怎麼會在WP查詢工作
<?php
function posts_orderby_lastname ($orderby_statement) {
$orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) ASC";
return $orderby_statement;
}
add_filter('posts_orderby' , 'posts_orderby_lastname');
?>
<?php $the_query = new WP_Query('post_type=person&posts_per_page=100');
while ($the_query->have_posts()) : $the_query->the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php endwhile;
remove_filter('posts_orderby' , 'posts_orderby_lastname');
wp_reset_query();
?>
這個工作