Updating with $qpdb->query() always returns 0 rows affected

wpdb uses PHP’s mysqli_affected_rows() or mysql_affected_rows(), which can be disabled via an argument in php.ini. I am guessing that that is what has happened. Check the disabled_functions line in your php.ini file and remove the references to those function. Of the top of my head, I am not sure if extensions like Suhosin mess with … Read more

Mysql query not working on WordPress 4.2.2

Try “bootstrapping” WordPress for your custom script first: include ‘../../../wp-load.php’ (you might need to adjust the path for your needs). Then you can safely use the $wpdb class, such as $wpdb->get_results and other goodies. Don’t forget to escape/clean your incoming data, if any. WordPress documentation on $wpdb PS: always try to use “builtin” functions. The … Read more

Get previous posts list

Did you chceck the Codex Date Parameters ? Expecially the ‘before’ param.It works like this: $date = get_the_date(‘Y-m-d H:i:s’); $args = array( ‘date_query’ => array( array( ‘before’ => $date ), ), ‘posts_per_page’ => 10, ); $query = new WP_Query( $args );

wp_posts query slowing down my website

Although a quarter of second is quite slow to query a single post from db, I’m convinced that this is not your only issue. I also use the Query Monitor plugin, but I have never really taken note when does the plugin redline a query as being slow. But that is not the point here. … Read more

Query for Custom Post Type UI Does Not Loop All the Post

Just found the answer.. Add posts_per_page in the arguments as -1. It should look like this: $args = array( ‘post_type’ => ‘lirik_melayu’, ‘posts_per_page’=> -1, // set the limit post to UNLIMITED (-1 is unlimited) ‘orderby’ => array( ‘ID’ => ‘DESC’ , ), ); $query = new WP_Query( $args ); $query_contents=Array(); while ( $query->have_posts() ) { … Read more

Customizing the_tags output?

Try this: $args = array( ‘taxonomy’ => ‘post_tag’, ‘hide_empty’ => 0 ); $tags = get_terms( $args ); $class_name=”my-custom-class-name”; if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) { shuffle( $tags ); foreach( array_slice( $tags, 0, 6 ) as $tag ) { printf( ‘<a class=”%1$s” href=”https://wordpress.stackexchange.com/questions/223735/%2$s”>%3$s</a>’, sanitize_html_class( $class_name ), get_tag_link( $tag->term_id ), sprintf( … Read more

get posts by tag to showing in a widget

You might want to go through: https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters So using tag parameter in WP_Query, you can get posts tagged to ‘video’ tag. Use orderby and posts_per_page to get last 5 video posts. $query = new WP_Query( array( ‘tag’ => ‘video’, ‘posts_per_page’ => 5 ) ); while ($wp_query->have_posts()) : $wp_query->the_post(); //your code to display posts endwhile; Haven’t … Read more

prepare function sql safe method

Both methods are okay ($new_wpdb->insert actually uses $new_wpdb->prepare) and provide the same level of safety when it comes to SQL escaping. $new_wpdb->insert is the preferred method unless you’re writing your own custom SQL query.

Optimize slow SQL query for multiple meta values

First you can optimize a little by not joining with wp_users as the joins can all be done between wp_usermeta. Another optimization would be to replace the WHERE clause with a subselect (which MySQL manages to optimize so it only gets executed once). The meta_key clause parts should be put into the WHERE clause I … Read more