Custom WP Query with neither ASC or DESC

Don’t think the effort worth it to do it with generating appropriate mysql statements as you can just use three queries, or sort the posts after you have the results of the query with both ways resulting in a mostly readable code. Main reason not to choose the above is if performance is critical. Another … Read more

Exclude page ID AND current page from wp_query of a Parent page

You can use get_the_ID() to retrieve the current page’s ID. $current_page_id = get_the_ID(); $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => ‘2’, ‘post__not_in’ => array( 4, $current_page_id ), ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’ ); This kind of ID exclusion may cause query performance issues, especially when you have a great number … Read more

Modify WordPress Search

You could try something like this below. Basically, if we are performing a search and it is the main_query (the query that generates the page results) ignore the default search and perform an exact match via the query_where function custom_product_search_exact_match( $query ) { global $wpdb; if ( is_search() && is_main_query() && !empty( $query->query_vars[‘s’] ) ) … Read more

WP-Query and Searching Inside Arrays

For array and object meta values, WordPress serializes them to string representations using serialize(). Thus, your meta value looks like this in the database: a:3:{i:0;s:9:”1 | 1 | 1″;i:1;s:15:”1.5 | 1.5 | 1.5″;i:2;s:12:”22 | 22 | 22″;} There is no built-in way to query within these serialized strings, but since these are strings with a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)