get_results using wpdb

global $wpdb; $result = $wpdb->get_results ( ” SELECT * FROM $wpdb->posts WHERE post_type=”page” ” ); foreach ( $result as $page ) { echo $page->ID.'<br/>’; echo $page->post_title.'<br/>’; }

Retrieve posts by term id custom query

Have you tried using the WP_Query class? You might find it’s easier to use the built-in tools for this instead of a custom query from scratch. Something similar to the following should work for you: <?php $args = array( ‘post_type’ => ‘recipe_cpt’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘recipe_tx’, ‘field’ => ‘term_id’, ‘terms’ => 37 … Read more

Query multiple custom post types in single loop

Just change the post_type bit to: ‘post_type’ => array(‘testimonial’, ‘other_post_type’, ‘another-post-type’), Assuming that taxonomy is valid across all 3 post types. Otherwise you’ll have to leave that out. Why? You can pass an array to post_type field.

Should we trust the post globals?

There is a sad truth: you can never ever be sure that some code will not break your code, and there is nothing you can do to prevent that. Especially in WordPress, where everything is global. That said, yes, global $post is one of the most used global var, so using special care for it … Read more

the_date() not working

See this special note about using the `the_date’ SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template … Read more

How to Optimize WP site for millions of posts

1. Set the query before WP_Query is run This seems to be the most important thing to keep in mind when trying to keep database queries to a minimum since the only opportunity to alter the query is, of course, before it is run in the SQL database. Normal Queries For a normal query, WordPress … Read more

Query multiple meta key values?

I feel like there’s an AND/OR confusion going on here. The queries in the OP will only return posts which have both key1 = ‘value1’ AND key2 = ‘value2’. Most WP plugins (that I know of, anyway) do not store multiple values in postmeta, for the same post, using the same key. If what you … Read more

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