Pull post name from value of a specific meta key

Here is a function that loops through all your posts and checks if the post_name is equal to your post_meta_value. If not it updates the post_name to whatever the post_meta value is. function wpse_get_update_posts() { $posts = get_posts( array( ‘posts_per_page’ => -1 ) ); foreach ( $posts as $post ) { if ( $post->post_name == … Read more

WordPress $wpdb no result

Your specific issue in that code is that you’re missing the quote marks around the $code. $query .= ‘WHERE code=”.$code; Should be: $query .= “WHERE code= “‘.$code.'”‘; In the long run, you should indeed use prepare() properly, but this is the specific problem with the code you posted.

Way to extract wordpress data from folder backup

There’s two elements to this: Restoring the mySQL database which hopefully resided in your wamp folder. This will be where the actual post data is in. See Restoring MySQL database from physical files Restore MySQL database folder from a recovered Hard Disk   Restoring the files themselves. The most straightforward way to do this will … Read more

querying user bookmarks from a large number of bookmarks

It looks like the default get_bookmarks() http://codex.wordpress.org/Function_Reference/get_bookmarks is using this query: SELECT * FROM wp_links WHERE 1=1 AND link_visible=”Y” ORDER BY link_name ASC; You can check the function in /wp-includes/bookmark.php. The get_bookmarks() function has limit and order parameters that you might find helpful. The option get_bookmarks(“limit=5”) gives this query: SELECT * FROM wp_links WHERE 1=1 … Read more

SQL Statement – Mass Delete Custom Post Types

Trust you have backed up your wordpress database. In any case, as the article suggests, worth trying with a select statement first to see which posts are returned: SELECT DISTINCT ID, post_title, post_type, post_status, d.taxonomy, e.name FROM wp_posts a LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id ) LEFT JOIN wp_postmeta c ON ( … Read more

WordPress VIP realpath Alternative?

I don’t know what “wp vip” wants or needs, but you should be loading files by means of get_template_part, locate_template, site_url, or home_url and I am guessing that using one or more of those is what the “scan” wants. It is hard to say exactly which since you posted only the error and not the … Read more

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 ) ); }

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