Sum custom field values of particular taxonomy

You would have to JOIN a couple of tables. SELECT meta_value FROM wp_postmeta as pm INNER JOIN wp_term_relationships as tr ON (pm.post_id = tr.object_id) INNER JOIN wp_term_taxonomy as tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE 1 AND tt.taxonomy = ‘laptop’ AND pm.meta_key = ‘quantity’ I am fairly sure that is right. These things are complicated. If … Read more

wp_editor not saving data, and text area showing html tags

There are a number of things going wrong in your code. I had to install it to see them all. First, You don’t want global $post. save_post will pass the post ID. Add a parameter to your callback. function save_points($post_id){ update_post_meta($post_id, “category”, $_POST[“category”]); update_post_meta($post_id, “brand”, $_POST[“brand”]); update_post_meta($post_id, “features”, $_POST[“features”]); update_post_meta($post_id, “holds”, $_POST[“holds”]); } Note: that … Read more

Multiple relationships in a query

Unfortunately, meta queries do not support a combination of AND & OR. But what you can do, is make two queries, one for each rule, then combine the results. $group_1 = get_posts( array( ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘meta_query’ => array ( array ( ‘key’ => ‘field1’, ‘value’ => ‘data1’, ), array ( ‘key’ … Read more

Update Custom post field by Ajax on cached site

I’ve spotted some errors here: jQuery.ajax({ type: “POST”, contentType: “application/json; charset=utf-8”, // default: ‘application/x-www-form-urlencoded; charset=UTF-8’. you can not set url: “http://localhost/wp-admin/admin-ajax.php”, // if you have correctly enabled ajax in wp, you should use the object you set up with the url data: “{‘action’:’get_PostViews(” + idpost + “)’}”, // you can use a PlainObject notation, so … Read more

How to save media files under custom folder without changing wp-config.php or changing media settings

Here is simple function to create your own sub directory for every upload. function kv_custom_image_dir( $pathdata ) { $subdir=”/uploads_img”.$pathdata[‘subdir’]; $pathdata[‘path’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘path’]); $pathdata[‘url’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘url’]); $pathdata[‘subdir’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘subdir’]); return $pathdata; } add_filter( ‘upload_dir’, ‘kv_custom_image_dir’ ); From my above code, I changed my images folder as uploads_img, you can change … Read more