Query posts based on previous query

As discussed in the comments, instead of using the ID query argument to get each ‘calp_event’-type post individually, you can pass an array of IDs to post__in in order to grab them all at once, thus reducing the number of database transactions in your code to 2. By creating an array mapping post IDs to … Read more

Query Nickname rather than Display Name in custom Woocommerce plugin

I had a similar problem and solved it similar to this: add_filter(‘pre_user_display_name’,’default_display_name’); function default_display_name($display_name) { if ( isset( $_POST[‘billing_first_name’] ) ) { $display_name = sanitize_text_field( $_POST[‘billing_first_name’] ); } return $name; } I think, the new woocommerce changes the disyplay_name on every checkout to First_Name Last_Name. With the ‘pre_user_display_name’ you can change your own way.

How to write update query in WordPress to expire transients

Transients are not guaranteed to use database at all. They will use object cache if it is enabled. And since there is no bulk delete in object cache API, effectively there is no reliable way to clear out transients across all possible environments. There are some performance reasons to clear them out of database (which … Read more

get_terms (or tax_query) for term of current post?

SOLVED This was what I was looking for and it works like a charm. function my_query_args($query_args, $grid_name) { $term_list = get_the_terms( get_the_ID(), ‘category’ )[0]->slug; if ($grid_name == ‘JTS-SINGLE’) { $query_args[‘tax_query’] = array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( $term_list ), ), ); } return $query_args; } add_filter(‘tg_wp_query_args’, ‘my_query_args’, 10, 2);

new WP_query > displays posts only once instead of running through full array

You can iterate over the array of IDs and look for the corresponding post in your results to generate output with duplicate posts: $post_ids = array( 208, 212, 218, 208, 212, 218 ); $args = array( ‘post_type’ => ‘custom_posttyp’, ‘order_by’ => ‘post__in’, ‘post__in’ => $post_ids, ); $the_posts = get_posts( $args ); foreach( $post_ids as $id … Read more

Modify date query by URL parameter using pre_get_posts and $_GET

I’m not where I can test this, but for something like: www.website.com/events?date=past, perhaps an approach like that outlined below could work. (I can almost guarantee a type or two, so be sure to rewrite/edit/rework this into your function and ensure you don’t inherit my errors). if (isset($_GET[‘date’])) { //using past, present, future as example. not … Read more

Random Page Rewrite

use this template in a single page <?php /* Template Name: Random3 */ ?> <?php $args = array( ‘numberposts’ => 1, ‘orderby’ => ‘rand’, ‘post_type’ => ‘food’ ); // get a random post from the database $my_random_post = get_posts ( $args ); // process the database request through a foreach loop foreach ( $my_random_post as … Read more

Query the WordPress database to get data together with replaced information

This query worked for me. I had to reverse it, starting at the user and then matching the post ID. You would need to replace the value of wp_posts.ID of course. SELECT wp_users.ID FROM wp_users LEFT JOIN wp_postmeta ON wp_postmeta.meta_value = wp_users.user_email AND wp_postmeta.meta_key = ‘_from_email’ LEFT JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id AND wp_posts.ID … Read more

Parse query filter in wordpress and relation

Since you are querying for multiple meta_key’s, you will want to put your meta_key queries in an array. A good example is this posting on StackExchange. For each of your functions you’ll want to replace the last three lines where you set the [‘meta_key’], [‘meta_value’], and [‘meta_relation’] with something like this: if( ! isset($query->query_vars[‘meta_query’]) ) … Read more