SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta

You can do something like Query the wp_posts table Left join the source_name from wp_posmeta table Left join the coverage_url from wp_posmeta table Then select the data you want to pull from post, source_name and coverage_url result Something like this should do SELECT post.ID, post.post_title, sn.meta_value as source_name, cu.meta_value as coverage_url FROM wp_posts as post … Read more

Pre_get_post on CPT archive page

pre_get_posts filters run before WordPress has figured out the main query, which is used to pick the template. For this reason you can’t put it inside the template, it has to run before the template is picked, not afterwards. For this reason, it has to go inside your themes function.php or in a plugin

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

Show post like this image in my newssite [closed]

I’m not sure what you’re asking for. If you need a simple query for a category. try generatewp.com for the fastest solution. Here’s how to code it yourself. https://codex.wordpress.org/Class_Reference/WP_Query you’ll want to use the Category_Parameters

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