Using OR conditions in meta_query for query_posts argument

Use ‘relation’ => ‘OR’ as in the Codex example below: $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( ‘relation’ => ‘OR’, /* <– here */ array( ‘key’ => ‘color’, ‘value’ => ‘blue’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘price’, ‘value’ => array( 20, 100 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) … Read more

Query *only* sticky posts

I currently have no posts set as stickies on the website. Which tells me that nothing should show up in the loop. Exactly where you are wrong when passing an empty array to post__in. WordPress has some silly bugs which has no proper workaround and will most probably stay active bugs for a very long … Read more

WP_query parameters for date range

Copied from StackOverflow: WP_Query offers a date_query parameter, allowing you to set a range with before and after. https://developer.wordpress.org/reference/classes/wp_query/#date-parameters $args = array( ‘date_query’ => array( array( ‘after’ => ‘January 1st, 2015’, ‘before’ => ‘December 31st, 2015’, ‘inclusive’ => true, ), ), ); $query = new WP_Query( $args ); See the linked documentation for more details. … Read more

Function in array as arguments for WP_Query

I suspect the problem is coming from $MyCustomField which you enter as such in: ‘terms’ => array( $MyCustomField ), The query consider it as only one value: ‘64,72’, a string. So try: $MyCustomFieldValues = array_map( ‘intval’, explode( ‘,’, $MyCustomField ) ); This will also ensure your values are integers. Then: ‘terms’ => $MyCustomFieldValues,

Make loop display posts by alphabetical order

To display posts in descending alphabetical order add this to your args array (taken from the wp codex) ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, To display posts in ascending alphabetical order just switch DESC to ASC. So the whole thing would look like: $args = array( ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ); $query = … Read more

Search custom taxonomy term by name

// We get a list taxonomies on the search box function get_tax_by_search($search_text){ $args = array( ‘taxonomy’ => array( ‘my_tax’ ), // taxonomy name ‘orderby’ => ‘id’, ‘order’ => ‘ASC’, ‘hide_empty’ => true, ‘fields’ => ‘all’, ‘name__like’ => $search_text ); $terms = get_terms( $args ); $count = count($terms); if($count > 0){ echo “<ul>”; foreach ($terms as … Read more

paginate_links() adds empty href to first page and previous link

Have you tried specifying the base and format arguments for paginate_links()? It assumes the default values of: ‘base’ => ‘%_%’, ‘format’ => ‘?page=%#%’, Your base should be something like /parent-page/child-page/%_%; then the first page link will be to /parent-page/child-page/, and subsequent links will follow the format /parent-page/child-page/?page=3 (example for page 3). In the base, the … Read more

tech