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

How do I query all posts of one type across my multisite installation?

Yes but not in a single query, e.g.: if(is_multisite()){ global $wpdb; $blogs = $wpdb->get_results($wpdb->prepare(“SELECT * FROM $wpdb->blogs WHERE spam = ‘0’ AND deleted = ‘0’ and archived = ‘0’ and public=”1″”)); if(!empty($blogs)){ ?><?php foreach($blogs as $blog){ switch_to_blog($blog->blog_id); $details = get_blog_details($blog->blog_id); $q = new WP_query(); if($q->have_posts()){ while($q->have_posts()){ $q->the_post(); // do things break; } } wp_reset_query(); restore_current_blog(); … Read more

Meta Query with AND & OR?

Sorry, doesn’t work that way. The “simple” meta parameters are converted into part of the meta_query as a whole. So it’s not a separate thing, and your OR relation applies to it as well. Your query thus is not possible with the normal query system, because you want to mix ANDs with ORs (you want … Read more

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