get_results using wpdb

I’m trying to retrieve information on my database. I wanted to display all pages using this statement, but I’m getting a blank ARRAY global $wpdb; $result = $wpdb->get_results ( ” SELECT * FROM $wpdb->wp_posts WHERE post_type=”page” ” ); echo $result; // display data Output: ARRAY EDIT: After changing below suggestions, I’m now using this. but … Read more

Retrieve posts by term id custom query

i want to retrieve custom posts using using custom query . my taxonomy is recipe_tx and terms (Beef) , (Chicken) etc in it . i have tried using SELECT p.* FROM wp_posts p, wp_term_taxonomy tt, wp_term_relationships tr WHERE p.ID=tr.`object_id` AND tt.`term_id`=tr.`term_taxonomy_id` AND (p.post_type=”recipe_cpt”) AND p.post_status=”publish” AND tt.`term_taxonomy_id` = 37 but no luck . can someone … Read more

Show a different number of posts per page depending on context (e.g., homepage, search, archive)

In the Reading Settings, there is place to set the number of posts shown that affects the number of posts shown in all contexts. I’d like to show instead a certain number of posts on the homepage, and a different number of posts on pages like archive, search results, etc. I realize I could do … Read more

Query multiple custom post types in single loop

I’m aware there are several other posts that cover similar ground to what I’m about to ask. I have three custom post types running, in addition to ‘posts’. I want to run a loop that pulls all posts categorised under a particular category <?php $args = array( ‘post_type’ => ‘testimonial’, ‘posts_per_page’ => 1, ‘tax_query’ => … Read more

the_date() not working

I am using wordpress 3.2 and I did a query post like this: <?php query_posts(“posts_per_page=1post=type&page=post_parent=10”);?> Then I try to echo out the date of this post I queried like this. <?php echo the_date(); ?> It gives me the title of the post and the excerpt and the permalink but no date. What do you think … Read more

Query multiple meta key values?

How to query for mutiple meta key values with the same key $querystr = ” SELECT $wpdb->posts.* FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = ‘key1’ AND $wpdb->postmeta.meta_value=”value1″ // why doesn’t this work? AND $wpdb->postmeta.meta_value=”value2″ AND $wpdb->posts.post_status=”publish” AND $wpdb->posts.post_type=”post” ORDER BY $wpdb->posts.post_date DESC “; next code <?php $args = array( ‘meta_query’ => array( … Read more

What SQL Query to do a simple find and replace

Whenever I create a new website I first create a staging site on a subdomain like “stage.domain-name.com”. After everything works correctly I export the database, open it in notepad++ and do a find/replace for “subdomain.domain-name.com” and replace it with “domain-name.com”… finally I import it into a new database for the live site. My question is… … Read more