SQL Query to select post title & post ID from a particular category

You can use $args = array( ‘post_type’ => ‘post’ ,’posts_per_page’ => 10, ‘category_name’ => ‘orange’ ); $query = new WP_Query( $args ); printf( ‘<h2>Generated SQL:</h2><pre>%s</pre>’, $query->request ); to display the generated SQL query. The above example will give you: <h2>Generated SQL:</h2> <pre> SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE … Read more

Retriving array size from serialized data

Your Query is wrong beacuse your are searching for the user_id inside the meta_value column instead of the user_id column. In this case i see no point in creating a custom query just for that, So here is how you can do it using the native function get_user_meta $data = get_user_meta( get_current_user_id(), ‘bookmark_posts’ ); $number … Read more

wpdb Cannot Access Associative Array Data in a Count Query

You can simplify that by using $wpdb->get_var. $total = $wpdb->get_var( “SELECT COUNT( * ) AS total FROM tableA” ); echo “Total Records:” . $total; However, the code you’ve got should work– either version of it. I tested both. The only thing I notice is that the first version of the code should give you Array … Read more

get unserialized array without using get_option()

You can use the following two inbuilt functions to do this. switch_to_blog get_option You can use both in the following way to make a function out of it which would give you the option. Put the below in the functions.php file function wpse_get_options( $blog_id = 1 ){ switch_to_blog( $blog_id ); $get_option = get_option( $option ); … Read more

wpdb select from using array as search parameters

Pass your information through prepare as in this example from the Codex: $metakey = “Harriet’s Adages”; $metavalue = “WordPress’ database interface is like Sunday Morning: Easy.”; $wpdb->query( $wpdb->prepare( ” INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s ) “, array( 10, $metakey, $metavalue ) ) ); Your array should have … Read more

looking for a way to allow users to backup the plugin db data(save as)

WP has Filesystem API to write files. However it can be relatively convoluted to implement (since it handles fallback for many cases and environments and workflow for requesting FTP crednetials from users) so often simply PHP functions are used to write file. Works reliably when constrained to uploads folder, otherwise need to be sure about … Read more

wpdb->update error

I’m not sure why you are using the the_date() function, but if you must, make sure it returns the value instead of echo-ing it. So instead of this part: array( ‘value’ => the_date(‘Y-m-d’) ), try this one: array( ‘value’ => the_date( ‘Y-m-d’, $before=””, $after=””, $echo = 0 ); ), To catch the update error, check … Read more

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