WP_Query – filter or directly?

You need to consider quite a couple of things here and it seems like you are after increasing performance of a query. The first and most important question you must ask yourself is: Do I need a custom query I have done an extensive post on this subject a while ago which you should check … Read more

Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)

should it be.. $paged = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1; WP_Query in codex: Pagination Note: You should set get_query_var( ‘page’ ); if you want your query to work with pagination. Since WordPress 3.0.2, you do get_query_var( ‘page’ ) instead of get_query_var( ‘paged’ ). The pagination parameter ‘paged’ for WP_Query() remains the same.

get custom post type by tag

You’ll need to setup the post for the query by changing the following line to get rid of the infinite loop. <?php while ($query->have_posts()) : $query->the_post(); ?> If your looking for a custom post type, you’ll need to specify that in the query arguments: <?php $query = new WP_Query( array( “post-type” => “yourposttype”, “tag” => … Read more

how does $wpdb differ to WP_Query?

The wpdb class is the interface with the database. WP_Query uses wpdb to query the database. You should use WP_Query when dealing with the native WordPress tables, to integrate your code properly with the WordPress environment. Use wpdb directly when you need to access data in your own tables.

Sort posts by category name and title

To get them broken down by Category, you need to loop through the list of categories and then query on each category: $categories = get_categories( array (‘orderby’ => ‘name’, ‘order’ => ‘asc’ ) ); foreach ($categories as $category) { echo “Category is: $category->name <br/>”; $catPosts = new WP_Query( array ( ‘category_name’ => $category->slug, ‘orderby’ => … Read more

Skipping first 3 posts in wp query

For skipping the post just use offset parameter in wp_query. To display latest three post : <?php $latestpost = new WP_Query(‘order=asc&orderby=meta_value&meta_key=date&posts_per_page=3’); //Here add loop to display posts like while($latestpost->have_posts()) : $latestpost->the_post(); the_title(); the_content(); endwhile; wp_reset_query(); //After that skip three posts using offset $latestpost = new WP_Query(‘order=asc&orderby=meta_value&meta_key=date&posts_per_page=6&offset=3&paged=’ . $paged); the_title(); the_content(); endwhile; wp_reset_query(); ?> That’s it

Search by Hyphen

One approach is to modify the exclusion prefix through the wp_query_search_exclusion_prefix filter that’s supported in WP 4.7+. See ticket #38099. Here’s an example how we can change it from – to e.g. !: add_filter( ‘wp_query_search_exclusion_prefix’, function( $prefix ) { return ‘!’; // adjust to your needs (default is -) } ); where we would use … Read more

tech