-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp_uqery.php
140 lines (108 loc) · 3.41 KB
/
wp_uqery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* WP_Query
*/
$args = array(
'post_type' => 'post', // page, post, project
'posts_per_page' => -1, // -1
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
endwhile;
else:
endif;
wp_reset_postdata();
/**
* Advanced WP_Query
*/
$page = get_query_var( 'page' );
$pages = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$sticky = get_option( 'sticky_posts' );
if ( is_front_page() ){
$pages = $page;
}
$args = array(
'post_type' => 'post_type', // page, post, project
'posts_per_page' => 5, // -1
'orderby' => 'menu_order', // rand, title, meta_value, meta_value_num, 'post__in', 'orderby' => 'comment_count'
'orderby' => array( 'post__in' => 'desc', 'title' => 'asc' ),
'order' => 'ASC', // DESC
'offset' => '1',
'post_parent' => get_the_ID(),
'post__not_in' => array('11'),
'post__in' => array('11','12'), // $sticky = get_option( 'sticky_posts' ); 'post__in' => $sticky
//'post_name__in' =>
//'post_parent__in' =>
//'name' => 'hello-world', by post/page name
//'pagename' => 'contact', by page name
'ignore_sticky_posts' => true,
'meta_key' => 'custom-filed-name', // views, get only post with thumbnail '_thumbnail_id',
'meta_value' => 1,
'cat' => array(1,2,3), // get categories and childrens
'category__in' => array(1,2,3), // get categories without childrens
'category__and' => array(1,2,3), // get posts if are in all categories
// 'category_name' => 'cat-slug,cat-slug-2',
//'paged' => $pages,
// 'post_status' => 'publish', // pending
'meta_query' => array(
array(
// 'compare_key' => 'LIKE', Meta query for wp 5.1
'key' => 'promo',
'value' => '',
'compare' => '!=', // '=', 'NOT EXISTS',
// must be only numbers
//'value' => '^[0-9]*$', // "misha_key" must be only numbers
//'compare' => 'REGEXP'
),
),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => array( $term->term_id ), // get_queried_object_id()
),
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'video' ),
'operator' => 'NOT IN',
)
),
'date_query' => array(
//'after' => '2 weeks ago',
'after' => '10 days ago',
'inclusive' => true,
),
);
//global $wp_query;
//$save_wpq = $wp_query;
//$wp_query = new WP_Query( $args );
$query = new WP_Query( $args );
$post_count = $query->post_count; // get count of post on current page $total_post_count = wp_count_posts();
$found_posts = $query->found_posts; // get count of all posts
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
the_title();
$post_name = get_post_field( 'post_name' );
//$current_post = $wp_query->current_post + 1;
// $index = $current_post;
// if ( is_paged() ) {
// $posts_per_page = $wp_query->query_vars['posts_per_page'];
// $paged = $wp_query->query_vars['paged'];
// $index = $current_post + ( $posts_per_page * ( $paged - 1 ) );
// }
// echo $index;
// // if is third
// if ( $index % 3 == 0 ) {
// echo 'third';
// }
endwhile;
the_posts_pagination(); // add_filter('navigation_markup_template', 'custom_navigation_markup_template', 10, 2 ); $template, $class
else:
endif;
//$wp_query = null;
//$wp_query = $save_wpq;
wp_reset_postdata();
//$wp_query = $save_wpq;