How to add next height number in Order Attributes inside the Add new page. [duplicate]

add_action( ‘admin_footer’, ‘my_action_javascript’ ); // Write our JS below here function my_action_javascript() global $wpdb; $pageposts = $wpdb->get_var(“SELECT max(menu_order) FROM $wpdb->posts WHERE post_status=”publish” AND post_type=”post_trainers””); ?> <script type=”text/javascript” > jQuery(document).ready(function($) { var data = { ‘action’: ‘my_action’, ‘whatever’: <?=$pageposts?> }; $.post(ajaxurl, data, function(response) { if($(‘#menu_order’).val()==” || $(‘#menu_order’).val()==’0′) $(‘#menu_order’).val(response); }); }); </script> <?php } add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ … Read more

Function returning queried meta value based on current post ID

You can still do the AS with $wpdb, I find it still makes stuff look cleaner. You can use the $wpdb->prepare() method for sanitation. Are you looking for something like this? function combined_downloads($post_id) { global $wpdb; return $wpdb->get_var($wpdb->prepare( “SELECT SUM( meta_value ) FROM $wpdb->postmeta AS m LEFT JOIN $wpdb->posts AS p ON m.post_id = p.ID … Read more

Custom database query to validate data

Assuming that all of your sql column names are correct, something like this should work: if(isset($_POST[‘submit’])){ global $wpdb; $tablename= $wpdb . ‘form_subscribe’; $myrows = $wpdb->get_var( $wpdb->prepare(“SELECT email FROM $tablename WHERE email=%s LIMIT 1″, $_POST[’email’])); if(empty($myrows)){ $data=array( ‘name’ => $_POST[‘fullname’], ‘age’ => $_POST[‘age’], ’email’ => $_POST[’email’] ); $wpdb->insert( $tablename, $data); } else { $status=”User already subscribed”; … Read more

How to set up prepared query using IN statement

My solution to the problem: $prepare = array(); $in = implode(‘,’, array_fill(0, count($product_ids), ‘%d’)); foreach ($product_ids as $ids){ $prepare[] = $ids; } $prepare[] = “post”; $prepare[] = $num; $results = $this->db->get_results($this->db->prepare(“SELECT ID, post_title FROM {$this->db->posts} WHERE ID NOT IN({$in}) AND post_type=%s ORDER BY ID DESC LIMIT %d”, $prepare));

Saving custom term value to the database in new table

short exmaple how i do it… (tables naming not really correct.) in this example i am trying to save _description $_POST variable. add_action ( ‘edited_term’, ‘custom_edited_term’, 10, 3); function custom_edited_term($term_id, $tt_id, $taxonomy){ if ( defined(‘DOING_AJAX’) || defined(‘DOING_CRON’) ) return; $_POST = stripslashes_deep($_POST); if (isset($_POST[‘_description’]) && trim($_POST[‘_description’]) != ”){ update_term_meta($term_id, ‘_description’, trim($_POST[‘_description’])); } else { delete_term_meta($term_id, … Read more

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