How to order posts by custom WP role?

you can add a custom field to each listing post with the user’s role and then in your query you can order by that field, for example say you have a custom field named `u_role’ then your query should look like this: $custom_role_query = new WP_Query( array( ‘author’ => implode( ‘,’, $custom_ids ), ‘post_type’ => … Read more

Looping through tabular data

The biggest problem here is syncing between two dissimilar sets of data. This looks like a good use-case for @scribu ‘s Posts2Posts plugin. Once you’ve installed that, you can create a direct correlation between the different post-types and query that connection.

Specific loop in Shortcode

Ok mate – i got you… you should really break into 2 shortcodes. One as a wrapper (which is really short) and the other for the content… Example: add_shortcode(‘servicewrap’, ‘service_wrapsc’); function service_wrapsc($atts, $content = null) { return ‘<div class=”service”><div class=”container”><div class=”row”>’.do_shortcode($content).'</div></div></div>’; } add_shortcode(‘servicesingle’, ‘service_singlesc’); function service_singlesc($atts, $content = null) { extract(shortcode_atts(array( ‘icon’ => ‘fa-briefcase’ ), … Read more

How to user WP_Query to lower the number of queries

The big issue you have here is calling your post thumbnails. That adds about two queries per post, which is quite heavy. When we look at the source code of get_the_post_thumbnail(), we will see that the thumbnails is only cached on the main query, and not custom queries. So we would need to do that … Read more

How to create posts (not post template) to be displayed on projects page?

The best way is to register a custom post type then loop through that type within your projects page template. CPT from GenerateWP. if ( ! function_exists(‘projects’) ) { // Register Custom Post Type function projects() { $labels = array( ‘name’ => _x( ‘Projects’, ‘Post Type General Name’, ‘text_domain’ ), ‘singular_name’ => _x( ‘Project’, ‘Post … Read more

Exclude posts with specific meta_value while sorting by a separate meta_value

You code may be $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘posts_per_page’ => ’50’, ‘meta_key’ => ‘release_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘undetermined_date_toggle’, ‘value’ => ‘true’, ) ), ‘paged’ => $paged ); $the_query = new WP_Query( $args ); this code show only those posts which … Read more

WP_Query meta_query by array key

You can’t do that. When you save postmeta (or any other meta, for that matter), WordPress runs it through maybe_serialize which turns objects and arrays into serialized data. When it gets pulled back out, it is run through maybe_unserialize. Serialized data looks something like this: a:1:{s:3:”one”;s:3:”two”;} In other words, what get’s stored cannot be queried … Read more

How to use global post counter in the loop?

As I already stated in a comment, You need to use get_option( ‘posts_per_page’ ) and get_query_var( ‘paged’ ) to calculate your post numbers You can do something like the following: (I have commented the code to make it easy to follow. This goes into functions.php) function get_post_number() { global $wp_query; /* * Get current page … Read more