new WP_Query to get max price meta value not working

As @Milo suggested and also codex documented it is_main_query Under_the_Hood This function is an alias for the method WP_Query::is_main_query(). In filter or action hook callbacks that are passed the WP_Query object, such as pre_get_posts, it is circular to call this function. Instead, directly call the passed object’s method. For example, if your filter callback assigns … Read more

Need wp_query to return all children and grandchildren

Ok, I found a solution. I first looped through and got all the child page ID’s, created an array, and used post_parent__in <?php $parentarray = array($parentid); $parentposts = new WP_Query( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘page’, ‘post_parent’ => $parentid ) ); while ( $parentposts->have_posts() ): $parentposts->the_post(); ?> <?php $parentarray[] = get_the_id(); ?> <?php endwhile; … Read more

Custom query for sidebar isn’t returning results

Based on our chat in the comments here’s what I came with. Please advise if it works. <?php function primary_category_query_shortcode( $post, $atts ) { //global $post; //Uncomment this global if it still doesn’t work. $atts = shortcode_atts( $defaults, $atts, ‘primary_category_query’ ); $my_meta = get_post_meta ( $post->ID, ‘_yoast_wpseo_primary_category’, true ); // WP_Query arguments $args = array … Read more

Query post order by post and desc not working

post is not a valid value for orderby parameter neither DESC. You can choose any of these values. Also, you should stop using query_post. <?php $args = array( ‘post_type’ => ‘ranking’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 10, ‘meta_key’ => ‘top10’, ‘meta_value’ => ‘sim’ ); $loop = new WP_Query( $args ); while ( … Read more

trim custom field text value and show (…)

building on keatch’s answer you only need to trim if its longer the 25 chars so: $trim_length = 25; //desired length of text to display $custom_field = ‘my-custom-field-name’; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { if (strlen($value) > $trim_length) $value = rtrim(substr($value,0,$trim_length)) .'(…)’; echo $value; }

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