Query on custom field count?

The following code allows you to add the parameters wpse4528_key and wpse4528_minimum to your queries, and will then add an extra criterium to the where clause that counts the number of meta values with your key. add_filter( ‘posts_where’, ‘wpse4528_posts_where’, 10, 2 ); function wpse4528_posts_where( $where, &$wp_query ) { global $wpdb; $count_key = $wp_query->get( ‘wpse4528_key’ ); … Read more

How to show custom field’s value under post/page title in wp-admin

Just like you add new columns you render the title filed your self add_action( ‘manage_posts_custom_column’, ‘admin_post_data_row’, 10, 2); function admin_post_data_row($column_name, $post_id) { switch($column_name){ case ‘title’: edit_post_link(get_post_title($post_id), ‘<p>’, ‘</p>’,$post_id); echo ‘<br />’.get_post_meta($post_id,’field_name’,true); break; default: break; } } and if you have another plugin cancels this then simply set the filter hook priority to something bigger.

WP Query group/order by category name

There are a few ways you can do this. The simplest is to just get everything: posts and terms, then use some array_filter magic to group things. Simple example (that will only work with PHP 5.3+): <?php $terms = get_terms(‘your_taxonomy’); $term_ids = array_map(function($t) { return $t->term_id, }, $terms); $posts = get_posts(array( ‘nopaging’ => true, ‘tax_query’ … Read more

custom field with total count of Facebook likes, comments and shares

I’ve done it, here is the complete code: function insert_facebook_likes_custom_field($post_ID) { global $wpdb; if (!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, ‘likes_count’, ‘0’, true); } } add_action(‘publish_page’, ‘insert_facebook_likes_custom_field’); add_action(‘publish_post’, ‘insert_facebook_likes_custom_field’); function update_facebook_likes($content=””) { global $wp_query; $permalink = get_permalink(); $idpost = $wp_query->post->ID; $data = file_get_contents(‘http://graph.facebook.com/?id=’.$permalink); $json = $data; $obj = json_decode($json); $like_no = $obj->{‘shares’}; $meta_values = get_post_meta($idpost, ‘likes_count’, true); if … Read more

add_meta_box: Datepicker like the one for postdate?

Never really thought about it, but it should indeed be a good option. The date picker is called from wp-admin/includes/meta-boxes.php (line 183) as: <div id=”timestampdiv” class=”hide-if-js”><?php touch_time(($action == ‘edit’),1,4); ?></div> and touch_time() is defined in wp-admin/includes/template.php (line 550) as: /** * {@internal Missing Short Description}} * * @since 0.71 * * @param unknown_type $edit * … Read more

ajax jquery update custom field meta value front end

First, you need to output a response in your my_action_callback() function. That response will be available inside your jQuery success callback: function(response){}. At that point it is just a matter of updating the HTML of the page with the new views count. PHP: function my_action_callback() { // … echo $views; exit; } JavaScript: jQuery.post(ajaxurl, data, … Read more

Multiple custom fields with the same name

Yes, it’s possible to have multiple fields with the same key. When using get_post_meta($post_id, $key, $single), make sure you set the $single parameter to false (or just leave it off since it defaults to false). get_post_meta( $post->ID, ‘Event Promotion’, false ) or get_post_meta( $post->ID, ‘Event Promotion’ ) This will return an array containing every value … Read more

Add Taxonomy Values Within a Custom Post Type RSS Feed

get_post_meta is only for custom fields. If listing_category and listing_type are in fact taxonomies, you need to use get_the_terms instead. The resulting code would be something like this: add_action(‘rss2_item’, ‘yoursite_rss2_item’); function yoursite_rss2_item() { if (get_post_type()==’listings’) { $fields = array( ‘listing_bedrooms’, ‘listing_city’, ); $post_id = get_the_ID(); foreach($fields as $field) { if ($value = get_post_meta($post_id,$field,true)) { echo … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)