Very slow query with meta_query on large database

It is recommended to stick with WP_query for grabbing WordPress posts; but, you can build your own queries directly from the postmeta table, then iterate through the results. Depending on the query, this may be faster (Not often; WordPress works hard to make their database queries as fast as they can be). global $wpdb; $table … Read more

Sort Popular Posts by Views for the Last Week

Use strtotime to compare dates. $start = strtotime(‘yesterday’); $end = strtotime( ‘+1 week’,$start); $args = array( ‘posts_per_page’ => 5, ‘ignore_sticky_posts’ => 1, ‘meta_key’ => ‘sw_post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘date_query’ => array( ‘after’ => $end, ‘before’ => $start, ), ); $popularpost = new WP_Query( $args ); if ( $popularpost->have_posts() ) { while ( … Read more

How to count data records in wordpress which have same meta_value in wp_postmeta table?

<?php global $wpdb; $table_name = $wpdb->prefix . “postmeta”; $login_name = sanitize_user( $_POST[‘parent_id’] ); $prepare = $wpdb->prepare( “SELECT COUNT(*) FROM $table_name WHERE meta_value=”Purva” AND meta_key = ‘parent_id’ “, $login_name ); $myrows = $wpdb->get_results( $prepare ); echo ‘<pre>’ . print_r( $myrows, true ) . ‘</pre>’; ?> I tried this and get values but still something missing…

Working Bootstrap Carousel Conversion to WP – Technical Questions

I had a similar situation recently, making a Bootstrap carousel dynamic. Here’s my functions.php code for that: //Images Slider function themename_slider_home_images_setup($wp_customize) { $wp_customize->add_section(‘home-slider-images’, array( ‘title’ => ‘Home Slider’, )); $wp_customize->add_setting(‘home-slider-first-image’); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, ‘home-slider-first-image’, array( ‘label’ => __( ‘First Image’, ‘theme_name’ ), ‘section’ => ‘home-slider-images’, ‘settings’ => ‘home-slider-first-image’ ) ) ); $wp_customize->add_setting(‘home-slider-second-image’); $wp_customize->add_control( new … Read more

meta_query problem

Meta queries aren’t intended for filtering which posts are returned. You can use them this way, but the database isn’t optimised for it. There are few things worse for scaling and performance than meta queries: Remote requests to other servers Modifying and rescaling images Queruing for what you don’t want ( e.g. show me all … Read more

Order by meta_key in custom post type doesn’t affect the query

Please have a look in the WP_QUERY improvement and the WP_QUERY Order & Orderby Parameters. $args = array( ‘post_type’ => ‘event’, ‘post_status’ => ‘publish’, ‘orderby’ => array( ‘meta_key’ => ‘ASC’ ), ‘meta_query’ => array( array( ‘key’ => ‘_start_eventtimestamp’, ‘value’ => date(‘Ymd’), ‘compare’ => ‘>=’ ), ), ); Hope it will work for you!

How to query ‘posts_per_page’ to display a different blog posts index template?

You can control what template loads for any type of query via the Template Filters. Here’s an example using home_template that checks if posts_per_page is equal to 1, and loads single.php in that case. function wpd_home_template( $home_template=”” ){ if( get_option( ‘posts_per_page’ ) == 1 ){ $home_template = locate_template( ‘single.php’, false ); } return $home_template; } … Read more

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