Assign custom parameter to each post in query

It’s a neat idea! The way I would tackle the problem is to create an associative array of post IDs mapped to their individual weights. Since weights are subjective – that is, the represent the value of other posts’ relationships with the post currently being displayed – it doesn’t make much sense to store these … Read more

How do I amend wp_query before it is run/executed?

Use pre_get_posts to modify the query object before the query has run. – https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-1,-1347’ ); } else if ($query->is_search) { $query->set( ‘s’, ‘stackoverflow’ ); } } add_action( ‘pre_get_posts’, ‘exclude_category’ );

Custom query with meta_key not working fine

@Rod0n WP version 4.2 included the number of improvements in WP_QUERY particularly when use the ‘meta_query’ parameter. Also, check the WP_QUERY Class Refernece. $args = array( ‘post_type’ => ‘proyectos’ , ‘posts_per_page’ => 8 , ‘paged’ => $paged, ‘orderby’ => array( ‘meta_value’ => ‘DESC’ ), ‘meta_query’ => array( array( ‘key’ => ‘wpcf-estado’, ‘compare’ => ‘EXISTS’, ), … Read more

Getting additional columns from sql

You need to add another join: INNER JOIN $wpdb->postmeta rate_review ON p.ID = rate_review.post_id Add the condition to your where clause: AND rate_review.meta_key = ‘rate_review’ Now you can add it to your SELECT: rate_review.meta_value AS rate_review

Get multiple users with meta value in one query and populate WP_User class

For anyone interested. Got it solved using the get_user_metadata filter to short circuit the metaquery and cache loading. Steps: Run query Store result data in the class property Add get_user_metadata filter Start foreach loop on results Trigger new WP_User( $result_value ) for each result Within the filter function, validate meta key on $wpdb->get_blog_prefix() . ‘capabilities’. … Read more

Query posts that contain video?

I don’t think there’s a fool-proofed way to do that, because the YouTube videos can be embedded in various ways and later be removed from the posts’ content. Here are few ideas: If you mean searching for e.g. the youtube string, then you could use the s argument in WP_Query. But the links might be … Read more