Is it bad to use a lot of Custom Meta Fields?

Custom Fields are normally fetched in a single query to the database, so fetching 1 or 10 isn’t going to make a lot of difference in performance of your WordPress site. The problem is with doing complex meta queries on existing custom fields; that’s when your site would see a performance hit. Obvious, isn’t it? … Read more

Title and post URL based on custom fields?

I think a good way to do what you want is hook the wp_insert_post_data filter. Here you can change the title and slug of the post before it is saved to database: add_filter( ‘wp_insert_post_data’, ‘wpse_update_post_title_and_slug’ ); function wpse_update_post_title_and_slug( $data ) { //You can make some checks here before modify the post data. //For example, limit … Read more

Conditional to modify query results

here is the mysql query you can use to get the result having distance less then your value. SELECT * , pm1.meta_value as latitude, pm2.meta_value as longitude , (((acos(sin(([latitude]*pi()/180)) * sin((pm1.meta_value * pi()/180)) + cos(([latitude]*pi()/180)) * cos((pm1.meta_value * pi()/180)) * cos((([longitude] – pm2.meta_value)* pi()/180))))*180/pi())*60*1.1515 ) as distance FROM wp_posts p JOIN wp_postmeta pm1 ON pm1.post_id … Read more

List the number of posts for each custom taxonomy and specific custom field value

The solution is: global $wpdb; $terms = get_terms(“TAXONOMY_TERM”); $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { $querystr = ” SELECT count(ID) as count FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE exists ( SELECT * FROM $wpdb->postmeta WHERE … Read more