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

get last post’s link with SQL query

Assuming each site is WP, they’ll both have RSS feeds. You’re better off just to fetch the RSS feed and get the latest post link from that. WP even has some built in support RSS parsing! <?php /** * An example of how to use fetch feed * * @uses fetch_feed * @return bool|string False … Read more

Get post featured image id with $wpdb

Haven’t tested it, but this should work: SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->terms.name, wpcflat.meta_value AS latitude, wpcflong.meta_value AS longitude, 6371 * 2 * ASIN ( SQRT (POWER(SIN(($lat – wpcflat.meta_value)*pi()/180 / 2),2) + COS($lat * pi()/180) * COS(wpcflat.meta_value *pi()/180) * POWER(SIN(($long – wpcflong.meta_value) *pi()/180 / 2), 2) ) ) AS distance, wpcfthumbnail AS thumbnail_id; FROM $wpdb->posts LEFT JOIN … 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.

SQL query – get ids – Advanced Custom Fields / WPeC

Thanks for your help s_ha_dum, I had a look at the table structure using phpMyAdmin, ACF Plugin saves fields to the postmeta table, so sb_wpsc_meta needed to be changed to sb_postmeta. also needed to change what was being SELECT to post_id aswell as the meta_value to 1. final query; “SELECT post_id FROM sb_postmeta WHERE `meta_key` … Read more

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

Help with Related Posts Function

You can use WordPress’s tax_query arg when fetching posts to achieve what you’re trying to do, this is also easily extendable with more than one taxonomy. $query = array( ‘post_type’ => $YOUR_POST_TYPE, ‘posts_per_page’ => -1 // get all ‘tax_query’ => array( ‘relation’ => ‘OR’ ) ); $query[‘tax_query’][] = array( ‘taxonomy’ => ‘YOUR_TAXONOMY’, ‘terms’ => $ARRAY_WITH_TERMS, … Read more