Can I create my own query in wordpress with traditional methods?

With some assistance from @JacobPeattie I modified the code to the recommended get_tags() function. Now in the functions.php I have the following code. // Get al the tags with published post function get_all_tags(){ $posttags = get_tags(”); if ($posttags) { foreach($posttags as $tag) { echo ‘<li><a href=”#”>’.$tag->name.'</a></li>’; } } } In the single.php file, I call … Read more

WP Query outputs three items within a div

You can use the variable $current_post, something like this. <?php $query = new WP_Query(array( ‘post_type’ => ‘custom_job’, ‘showposts’ => 12 ) ); ?> <?php while ($query->have_posts()) : $query->the_post(); ?> <?php if ($query->current_post % 3 === 0) :?> <?php $numbers = array(‘One’, ‘Two’); //add the rest ?> <div class=”jobs<?php echo $numbers[floor($query->current_post / 3)];?>”> <?php endif;?> <div … Read more

3 queries to update WordPress

Sounds like you’re trying to do it the old and hard way. When you add a fresh install of WordPress, it will ask you for the database information. You would need to create a mySQL database, set a user for that database, and then import the contents from the old database to the new one … Read more

WooCommerce Total # orders [closed]

You can use this following query to get the total number of orders. $order_totals = apply_filters( ‘woocommerce_reports_sales_overview_order_totals’, $wpdb->get_row( ” SELECT COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id ) LEFT JOIN {$wpdb->terms} AS … Read more

Query parsing only author ids

Assuming that you have an array of post objects in $my_posts… $authids = array_unique(wp_list_pluck($my_posts,’post_author’)); What you will get are the post authors for the current page of posts, not the post authors for all of the posts. If you want the authors for all of the posts you will have run another query. To run … Read more

Custom Query for wp_posts using wp_postmeta

While you might not want / be able to use native query, it is still the easiest and most reliable way to generate SQL like that. $wpdb->last_query will remember last query performed and defining SAVEQUERIES constants will make $wpdb->queries contain all of the queries performed in current load (not advisable in production for performance). So … Read more

query posts only works on the first page

As @Pieter Goosen said, you shouldn’t be using query_posts, nor running your own query. Instead, override the main query that already runs: function wpse_144974_pre_get_posts( $wp_query ) { if ( ! is_admin() && $wp_query->is_main_query() && is_home() ) $wp_query->set( ‘cat’, 1 ); } add_action( ‘pre_get_posts’, ‘wpse_144974_pre_get_posts’ );