WordPress post_where & posts_join not working only for custom post type
WordPress post_where & posts_join not working only for custom post type
WordPress post_where & posts_join not working only for custom post type
i have found a solution, making a custom SQL query here is the code ( using WPML ) $startday = date(“Y-m-d”); if ( defined( ‘ICL_LANGUAGE_CODE’ ) ) { $lang = ICL_LANGUAGE_CODE; } //echo $startday; global $wpdb,$post; $results = $wpdb->get_results( “SELECT * FROM wp_posts, `wp_mec_dates` AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status=”publish” AND wp_icl_translations.language_code=”$lang” … Read more
thanks for your time and thanks to @czerspalace I started the query with double quotation and then separate it with a single quotation and after looking at the echo output I found that there’s no spaces between From and table name this is the correct way $pending_reservations = $wpdb->get_results(‘ SELECT booking_calendars.cal_name FROM ‘.$wpdb->prefix.’booking_calendars AS booking_calendars … Read more
Always escape/prepare your data Don’t leave it open to injections: global $wpdb; $all_posts = $wpdb->get_results( $wpdb->prepare( ” SELECT %s.* FROM %s LEFT JOIN %s ON(%s = %s) WHERE %s=”soundcloud” AND %s=”%s” ” ,$wpdb->posts ,$wpdb->posts ,”{$wpdb->prefix}soundcloud” ,$wpdb->posts.ID ,”{$wpdb->prefix}soundcloud.idpost” ,$wpdb->posts.post_type ,$wpdb->posts.post_name ,$name ), OBJECT ); echo ‘<pre>’.var_export( $all_posts, true ).'</pre>’; Use the prefix $wpdb; offers the $wpdb->prefix, … Read more
$emailusers = $wpdb->get_results( “SELECT p.ID AS post_id, p.post-title, u.user_email ” . “FROM $wpdb->posts AS p ” . “INNER JOIN $wpdb->users AS u ON p.post_author = u.ID ” . “WHERE p.post_type=”sales” AND HOUR( TIMEDIFF( NOW( ) , p.post_date_gmt ) ) >=1)” ); foreach ($emailusers as $user) { // do wp_mail stuff from here // $emailusers->post_title; // … Read more
add this in your arguments ‘query_id’ => ‘authors_with_posts’, $user_args = array( ‘role’ => ‘frontend_vendor’, ‘orderby’ => ‘display_name’, ‘query_id’ => ‘authors_with_posts’, ‘order’ => ‘ASC’, ‘number’ => $no, ‘offset’ => $offset );
This seemed to do the trick, running it before my WP_Query: $wpdb->query(‘SET OPTION SQL_BIG_SELECTS = 1’);
After some hard work and research, I finally came up with this working solution. Please feel free to improve on this code and post an alternative answer. For some reason, the query seems to be running more than once (three to four times in my case). Here, I am making use of three hooks, posts_search, … Read more
Well, after trying different things, I came up with the following. When we use posts_join there is no need to add the prefix $wpdb-> plus the table being queried. We just need the column name. In this case, we just need name and taxonomy, like this: BEFORE $where .= ” OR ($wpdb->term_taxonomy.taxonomy IN (‘category’) AND … Read more
So based on our discussion, the meta named opposition (for match posts) has its value set to the slug of the corresponding club post; e.g. club-1, club-two, etc., right? If so, then you first get the ID of the club post using a custom query (see in the code below) and then you can access … Read more