- Lấy post cụ thể:
- Nếu post đó là một attachment thì sử dụng 'attachment_id' thay vì 'p'
query_posts( 'attachment_id=5' );
|
Tham khảo các tham số hay sử dụng để lọc dữ liệu trong wordpress:
<?php
// WP_Query arguments->example of wp_query arguments generator from http://generatewp.com/
$args = array (
'name'=>'sample-post-slug',
'post_type' => 'posttype1',
'post_status' => 'publish', #'publish', 'draft',..
'cat' => '12,3,5,7',
'category_name' => 'cate1',
'author' => '5',
'author_name' => 'user1',
's' => 'find string',
'pagination' => true,
'paged' => '3',
'posts_per_page' => '50',
'ignore_sticky_posts' => true,
'offset' => '37',
'order' => 'ASC',
'orderby' => 'rand',
'year' => '2002',
'monthnum' => '2',
'day' => '23',
'meta_query' => array(
array(
'key' => 'custom-field1',
'value' => 'field-value',
'compare' => '!=',
'type' => 'NUMERIC',
),
),
);
// The Query
$query = new WP_Query( $args );
?>
|
- Loại bỏ post ra kết quả tìm kiếm.
$args=array(
'post__not_in' => array($post->ID),
);
|
- Trả về toàn bộ posts có thumbnail/feature image.
Chú ý: Những post có thiết lập feature image thì tồn tại meta '_thumbnail_id'.
$args=array(
'meta_key' => '_thumbnail_id',
);
|
Unregistered version