$wpdb->update Issue
array( ‘id’=> $result=>id ), should be array( ‘id’=> $result->id ), I suspect that’s your white screen issue.
array( ‘id’=> $result=>id ), should be array( ‘id’=> $result->id ), I suspect that’s your white screen issue.
If that is the complete code for ste.php then you are loading it without any WordPress context, which means that functions like wp_insert_post are not going to be defined. If you check your server logs you will probably see errors to that effect. The easy, and I’d argue the best, solution to this is to … Read more
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
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 ) );
Refer to the Codex page for setup_postdata(): Important: You must make use of the global $post variable to pass the post details into this function, otherwise functions like the_title() don’t work properly… Also note that you can use WP_Query to do these queries, rather than writing raw SQL.
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
My guess is that this is the wrong hook for what you are trying to do, or you are using it incorrectly. A few notes: You are passing unvalidated data into a query. Please don’t do that. This… $town_b = $_POST[‘item_meta’][800];//Gets the value from the first field global $wpdb; $query = “SELECT County FROM wp_locations … Read more
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
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/>’; } ?>
$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