Add meta value to custom post type on publish

You are usgin an undefined $post->ID variable because there is no reference to any $post object in your code; instead, use the $post_ID variable retrieved in the function: function on_jobs_publish( $post_ID ) { global $wpdb; $wpdb->insert( ‘iCrewzWp_postmeta’, array( ‘post_id’ => $post_ID, ‘meta_key’ => ‘_yoast_wpseo_sitemap-include’, ‘meta_value’ => ‘always’ ), array( ‘%d’, ‘%s’, ‘%s’ ) ); } … Read more

Doubt using $wpbd->get_col for a single column

Try this. Hopefully I’ve interpreted your output correctly. I’d recommend a good read of the $wpdb codex, particularly in relation to the get_col() method – http://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column global $wpdb; // You won’t need this unless this code is within a function $query = $wpdb->prepare( ‘SELECT %1$s.guid FROM %1$s’, $wpdb->posts ); $results = $wpdb->get_col($query); $counter = 1; … Read more

WSoD being caused by this piece of code

You have a problem with your code formatting and syntax at the very least: function ref_access(){ global $error; if (is_user_logged_in()) // <– problem here… $newdb = new wpdb( ‘user’, ‘pass’, ‘db’, ‘localhost’ ); global $newdb; $hf_username = wp_get_current_user(); $inputValue = $_POST[$quanid]; $wpdb->insert( $table, array( ‘ItemID’ => $quanid ‘Price’ => $inputValue ‘user’ => $hf_username ), ); … Read more

Issue regarding $wpdb->prepare()

prepare() is used to escape the values for example in the WHERE-statement. Usually it is anticipated the table selection is “hardcoded”. If you can’t use for example $wpdb->posts or the other “table”-functions, you could whitelist the allowed tables and check if $table_name is on this white list: <?php $allowed_tables = array( $wpdb->prefix . ‘nametbl’, $wpdb->prefix … Read more

Get an array of meta_values for a user meta_key

You just need to add a DISTINCT to your SQL query, something like: $cities = $wpdb->get_col(“SELECT DISTINCT(meta_value) FROM $wpdb->usermeta WHERE meta_key = ‘my_cities_meta_key'” ); Alternatively, if you want to do it with php for some reason (if you want to know that a city is listed twice before displaying only unique entries) $cities = $wpdb->get_col(“SELECT … Read more

Getting id of poll from WP database

The first problem I spotted is that you aren’t setting $latest_pollid but you are nonetheless trying to use that as the poll id. You should have something like: $latest_pollid = polls_latest_id(); before that line in order to set the value. There are big problems with what you are doing though. Hooking to after_setup_theme means that … Read more

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