I'm using the plugin Modern Events Calendar Lite. This is a recent plugin, so actually no doc exist. So i'm looking a way to display my upcoming events on homepage. But i can not make it to work, because start is stored in a second table. So i have a wpquery that list custom posts "mec-events", this is ok. But i'm not able to JOIN info to second table to get start_date & to order posts on its value. I …
I have constructed a custom plugin that stores data in a custom DB table relating to the viewing activity of users who have a custom role of 'attendee' on a custom post type page called 'presentations'. I have produced a report of this activity visible to administrators as follows: <?php global $wpdb; $results = $wpdb->get_results('SELECT v.user_id, v.video_id, v.last_updated, v.watch_data, u.user_login, u.user_email FROM wp_video_tracking AS v INNER JOIN wp_users AS u ON u.ID = v.user_id ORDER BY last_updated DESC'); $table_row = …
I have a custom WordPress plugin built for booking courses etc. My custom plugin has some new tables in which custom data like slot date, time etc are stored. I am trying to modify archive query for courses so it is ordered by slot date from another table so i am using posts_join hook to LEFT JOIN my courses table with posts table and then posts_orderby to order results by slot_date I want to run this only on my courses …
I have built a posts query that includes a custom table in search using the posts_join and posts_where filters. Now the customer wants me to include yet another custom table in the search, but doing so increases query time from an instant to over 5 seconds. This is what I have done: function my_posts_join( $join ) { global $wpdb; $old_table = "wp_some_custom_table"; $new_table = "wp_another_custom_table"; if ( is_search() ) { $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . …
Hi – I'm hoping this is the right place to be asking this question. I am in the process of moving my full football club website onto Wordpress, therefore using a single database for the information I hold. I'm doing this (for context) to make things easier in the long-run. Before, there was a database table for Opponents, Matches, Players etc. Now I have Custom Post Types for these. Each entry in these tables has a unique ID that could …
Based on the premise that one big database requests is better than many smaller ones, I've modified WP_Query for my custom post type 'word' and joined three tables to it. The resulting query looks more or less like this and works well. SELECT wp_posts.*, verbs.*, nouns.*, definitions.* FROM wp_posts LEFT JOIN verbs ON ( wp_posts.ID = verbs.word_id ) LEFT JOIN nouns ON ( wp_posts.ID = nouns.word_id ) LEFT JOIN definitions ON ( wp_posts.ID = definitions.word_id ) WHERE 1=1 AND wp_posts.post_type …
i'm working on a music plugin. It uses a custom table tracklist_items to store every tracks of a playlist; which has a structure like this : |id| |track_id| |tracklist_id| |order| |time| So if I want to count the total tracks of a tracklist, I have this function : function get_subtracks_count(){ global $wpdb; if (!$this->post_id) return false; $querystr = $wpdb->prepare( "SELECT COUNT(*) FROM `tracklist_items` WHERE tracklist_id = %d", $this->post_id ); return $wpdb->get_var($querystr); } But now, I would like to be able …
I am trying to use the posts_join filter to join 2 tables: wp_postmeta to wp_posts. I am a novice at SQL, so I'm not sure if I am confused because I don't understand how WordPress is implementing posts_join, or if I just don't understand the SQL syntax. My questions are: Why is only one table used in the join statement? I thought 2 tables were needed for a join statement Is this because the posts_join filter assumes you are always …
I have a table that populates data pulled from ACF. It basically adds a PDF of a report if there's one available. I think I got that part figured out, but my code is awfully complicated and I'll like to simplify it with a switch statement or something similar. Also, how do I get the table to display a value of 'x' when there's no PDF file available? It's currently removing the cell and I don't want it to do …
I'm currently testing some features on a sandbox environment. I have an existing production website and I'd like to ship my production users and other related tables on new sandbox environment. While doing this, I'd like to retain users on sandbox. I have used CSV export, editing IDs through Excel but importing is adding extra quotes or splitting columns due to commas. Any ideas? I know that some of the issues are caused by my regional settings on Windows however …
Hi Im trying to run 2 querys in the same query call. // send the query global $wpdb; $commentQ = "SELECT * FROM $wpdb->comments " . $whereClause . $orderBy; $comments = $wpdb->get_results( $commentQ, ARRAY_A); So far it works , but when i try to run 2 querys it fails. What I wanna do is i want to run: **SELECT * FROM `wp_88_commentmeta` ORDER BY `wp_88_commentmeta`.`meta_value` ASC LIMIT 0 , 30** Im trying to get the meta_value only from that table. …
I'm in need of someone who knows MySQL better than I do! I've started writing a custom statement, but I'm not an expert with mySQL and it's not quite there (I'm happy to scrap it entirely if there's a better way to do it!) Here's what I'm trying to do... Retrieve a SINGLE user_id where the users meta_key _wcv_store_icon_id has a value (not including empty string). The results must be ordered by promo_count. The issue I'm having is that promo_count …
I have a custom query where I need a JOIN because I want to COUNT all the posts of a specific category. So I checked the tables and I found out that table wp_term_relationships contains a reference to the wp_term_taxonomy table. The term_taxonomy_id. However when I looked into the wp_term_taxonomy table again I found out that term_taxonomy_id and term_id are having the exact same values. So are they always the same? Can I filter the results by category with only …
I have a problem in writing SQL Inner Join syntax in wordpress, This logic should definitely work, I tried this in phpmyadmin and it works fine SELECT booking_calendars.cal_name FROM booking_calendars INNER JOIN booking_reservation ON booking_calendars.id = booking_reservations.calendar_id WHERE status LIKE 'pending' but it doesn't in wordpress $pending_reservations = $wpdb->get_results(" SELECT booking_calendars.cal_name FROM'.$wpdb->prefix.'booking_calendars AS booking_calendars INNER JOIN' . $wpdb->prefix.'booking_reservation AS booking_reservations ON booking_calendars.id = booking_reservations.calendar_id WHERE status LIKE 'pending'"); and then echo "<h2>Pending Reservation: </h2><br>"; var_dump( $pending_reservations); if($pending_reservations>0) { foreach ( …
I have this query so far : $user_args = array( 'role' => 'frontend_vendor', 'orderby' => 'display_name', 'order' => 'ASC', 'number' => $no, 'offset' => $offset ); $user_query = new WP_User_Query( $user_args ); Now what I want to do is to get all users that has only posts, i have an example query that i want to do. how do i do this with wp_query()? SELECT users.id, posts.id FROM wp_users RIGHT JOIN wp_posts ON wp_users.id = wp_posts.user_id WHERE wp_posts.post_type = 'downloads' …
I am trying to view a list of users (who are music artists) with the following function. function show_authors($ltr) { global $wpdb; $querystr = "SELECT $wpdb->users.* FROM $wpdb->users WHERE $wpdb->users.display_name LIKE '$ltr%' ORDER BY $wpdb->users.display_name"; /** $querystr = " SELECT * FROM $wpdb->users INNER JOIN $wpdb->usermeta.meta_value ON $wpdb->users.user_id = $wpdb->usermeta.user_id AND $wpdb->usermeta.meta_key = 'wp_capabilities' AND $wpdb->usermeta.meta_value = %artist% WHERE $wpdb->users.display_name LIKE '$ltr%' AND $wpdb->usermeta.meta_key = 'wp_capabilities' AND $wpdb->usermeta.meta_value LIKE '%artist%' ORDER BY $wpdb->users.display_name ASC "; **/ $users = $wpdb->get_col($querystr); echo …
Regarding answer provided by birgirethis to this post: wp-query-to-show-post-from-a-category-or-custom-field I found one issue with your solution. The two inner joins (term_relationships and postmeta) will only get results when a specific post has at least one term_relationship entry, otherwise the query won't fetch that post and will get a faulty result. How do I modify the code to get the expected results? Thanks!
I have a post type "shows" with 500 posts in it. I want to list all 400 in one page listing their title + 5 meta fields and a url to the show post thumbnail. I initially went the classic wordpress way by using a custom WP_Query, looping through them with appropriate template tags such as the_title() and get_post_meta(). But the page loads very slowly. So I've done some profiling with xdebug+webgrind and it turns out that it is expensive …
For the last few hours, I have been trying to use the filter hooks posts_where and posts_join to search for posts based on taxonomy terms, in this case, the taxonomy is 'category' and the term is 'politics' This is what I tried and resulted in a empty query: This line is inside the hook posts_where $where .= " OR ($wpdb->term_taxonomy.taxonomy IN ('category') AND $wpdb->terms.name = 'politics')"; And this is what I used to join the different tables: $join .= " …