0

我正在尝试获取带有标题元值的最新帖子,但它给了我最新的帖子。这是我的查询,我做错了什么?

$querydetails = "
        SELECT $wpdb->posts.* 
        FROM $wpdb->posts, $wpdb->postmeta
        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id  
        AND $wpdb->postmeta.meta_value = 'headline'
        AND $wpdb->postmeta.meta_key = 'custom_select'
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
        ORDER BY $wpdb->posts.post_date DESC
        LIMIT 1
    ";

    $headline = $wpdb->get_results($querydetails, OBJECT);
4

1 回答 1

1

您应该在wp_query中执行此操作,
下面的代码应该执行此操作。

<?php
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'meta_key' => 'custom_select',
    'meta_value' => 'headline',
    'posts_per_page' => '1', //limit
    'paged' => get_query_var( 'page' ),
    'order' => 'DESC',
    'orderby' => 'date'
);
$query = new WP_Query($args);
?>

这样您就可以像the_content()循环中一样使用默认的 wordpress 标签

于 2012-04-16T09:51:32.817 回答