add_post_meta — not working

What user34296 said is update_post_meta() will update the value of the existing meta key (custom field) for the specified post. If it does not already exist it will call add_post_meta($post_id, $meta_key, $meta_value) instead. That’s why you should use it. EDIT: in this case it should work, error is coming from another part of the code. … Read more

select a single val though a table in wordpress

Use the method get_var() instead. I’ve also tidied up your code (if you’re gonna use double quotes, take advantage of them!) & added data escaping with the handy prepare() method. global $wpdb; $cat_id = $wpdb->get_var( $wpdb->prepare( “SELECT category_id FROM {$wpdb->prefix}awpcp_categories WHERE category_name = %s”, $ad_cat ) );

WordPress Mysql query and Duplicate

There’s no need for custom SQL here, use the power of meta queries: $posts = get_posts( array( ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘Country’, ‘value’ => ‘UK’, ), ), ) ); foreach ( $posts as $post ) $cities[] = get_post_meta( $post->ID, ‘city’, true ); foreach ( array_unique( $cities ) as $city ) … Read more

Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin

In a comment you clarify: what i meant by running is going to the url (mysite.com/wp-content/plugins/myplugin/checkrank.php?id=1) In that case, you are running a standalone file. Yes, one that resides inside WordPress’ plugins folder, but you don’t access it in the context of WordPress (i.e. from within it). Here, none of the WordPress core functions/methods/classes will … Read more

query a newly created table using $wpdb

you doing something wrong your $result query returns multidimensional array of rows and each row has an array of keys values, try this, not tested but will work. <?php global $wpdb; $result = $wpdb->get_results ( “SELECT * FROM $wpdb->forms” ); foreach ( $result as $key => $row ) { echo $row->ID.'<br/>’; } ?>

Can I use wpdb to insert query results into a post?

$wpdb is a relatively simple wrapper around PHP’s mysql functions. If you can do it with PHP/SQL then you can do it with $wpdb. You’re question is not detailed or specific enough to afford a more detailed answer though. Nor is it detailed enough to say whether $wpdb is the best, or even an acceptable` … Read more

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