Intentionally exceed max_num_pages on main query without getting 404?

On every page load, WordPress executes these functions in their respective order: init(); parse_request($query_args); send_headers(); query_posts(); handle_404(); register_globals(); where the main query is finished after query_posts(). Note that in this point in time, WordPress knows the template AND all the query variables like max_num_pages. In handle_404(), if the main query has any posts, the function … Read more

tax_query shows no results if nothing is selected

So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET[‘suburbs’] ) ) { $suburbs = $_GET[‘suburbs’]; } // States if( !empty( $_GET[‘states’] ) ) { $states = $_GET[‘states’]; } // Query arguments. $args = array( ‘post_type’ => ‘properties’, ‘posts_per_page’ => 10, ); $taxquery = array(); // if … Read more

How to detect custom query inside `posts_where` hook?

If we have the query arguments like this $args = array( ‘queryid’ => ‘blackjack’, … ); $q = new WP_Query( $args ); Note we added one custom query argument that is not officially present in here. Now we can identify the exact query by that queryid if we use the second parameter of the posts_where … Read more

How to show only one post for each categories of taxonomy of custom post that contains a specific custom field

<?php // get all terms of the `bank` taxonomy $banks = get_terms( array( ‘taxonomy’ => ‘bank’, // more arguments can be used, see (1) below the code ) ); // look through banks, picking one post from each foreach ( $banks as $bank ) { $args = array( ‘post_type’ => ‘account’, // your custom post … Read more

Finding post content that begins with a specific character

Something like this will probably work: $results = array(); $allPosts = get_posts(‘post_type=post&numberposts=-1’); foreach ($allPosts as $aPost) { if ( substr($aPost->post_content, 0, 1) == ‘<‘ || substr($aPost->post_content, 0, 2) == ‘<a’ ) $results[] = $aPost->ID; } echo “<pre>”.print_r($results,true).”</pre>”; UPDATE: but you should revisit the MySQL approach in the links you provided. This php method is somewhat … Read more

WP_Query Filtred by author name ( Return null )

That’s not how WP_Query works, it isn’t what the documentation says either. WP_Query is not a function. foreach needs an array, or something that can be iterated on, but you’ve given it a WP_Query object. Instead, look at the documentation or tutorials, all of them follow this basic pattern for a standard post loop: $args … Read more

Should close $wpdb via $wpdb->close()

The close() function was added for completeness in the database abstraction. If the database is prematurely closed in a plugin or theme (as you are using it), the next call to wpdb::query() will re-open the connection. Your Commands out of sync error is a MySQL error, not a WordPress one, and it might be coming … Read more

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