Help setting up a sql query

Ok, if i understand you clearly, then this is the solution // first get the post ids that have the breakfast food type $post_ids = $wpdb->get_col( “SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = ‘type’ AND meta_value=”Breakfast”” ); // now get the food names $stocktypes = $wpdb->get_col( “SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = … Read more

Create an user on external database

No matter how you create a new user, it will end up calling wp_insert_user, which runs the action user_register right before finishing. So you can do something like the following: add_action(‘user_register’,’register_user_remotely’); function register_user_remotely($user_id) { //add user to external database $url = …; //url of file that will receive the $user->data in the $_POST variable $user … Read more

Query multiple meta key values for template

No idea why you’re using clunky custom SQL, use a meta query instead. $pageposts = get_posts( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘_wp_page_template’, ‘value’ => array( ‘templates/front-page-excerpt.php’, ‘templates/front-page.php’, ) ) ), ) );

Calling mysql_query() on another database, assumes WordPress using that database

Use a new instance of wpdb to connect and read from the other database: $mydb = new wpdb(‘blah’,’blah’,’dkpldump’,’localhost’); $event_categories = $mydb->get_results(“SELECT * FROM calendar_cats”); foreach( $event_categories as $event_category ){ //create term! $term = wp_insert_term( $event_category->categoryId, ‘event_category’, array( ‘slug’ => $event_category->categoryName ) ); }

Using mysql to replace img src?

This feels like it is too link-heavy for an answer, but oh well. You can either use the Velvet Blues Update URLs plugin or the Serialized Search and Replace script. Either will allow you to search for a string in the database and change it to something else. The former lets you do it from … Read more

Query the database after get_header() has been included

Your question is vague: i’ll try to be as specific as possible. The basic rule is: if you need to modify the default query, use pre_get_post If you need to display another list of results than the one linked to your template url, use get_posts. I find this documentation to be quite useful http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/ Doc … Read more

List users with the most posts in the last 30 days

Here is what you need. <?php $date = new DateTime(‘NOW’); $date->sub(new DateInterval(‘P30D’)); //30 Days Interval echo $back30days= $date->format(‘Y-m-d H:i:s’) . “\n”; global $wpdp; $top_users = $wpdb->get_results(“select count(users.user_nicename) as posts, users.user_nicename as user_name from $wpdb->users as users join $wpdb->posts as posts where users.ID = posts.post_author AND posts.post_status=”publish” AND posts.post_date_gmt > ‘$back30days’ GROUP BY users.user_nicename ORDER BY … Read more