How to display specific data from a custom table to logged in users with a custom role
How to display specific data from a custom table to logged in users with a custom role
How to display specific data from a custom table to logged in users with a custom role
If you are going to do this is SQL, use a subquery. SELECT *, (SELECT meta_value FROM wp_commentmeta WHERE meta_key = ‘your-meta-key’ AND wp_commentmeta.comment_id = wp_comments.comment_ID LIMIT 1) as comment_author FROM wp_comments Instead of the *, enumerate the fields you want but leave out comment_author. Obviously, $wpdb functions to keep the table names straight.
Check WP_Query Order by Parameters $args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_key’ => ‘age’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array(3, 4), ‘compare’ => ‘IN’, ) ) ); $query = new WP_Query($args);
There are few things you should remember when you’re using SQL in WordPress. The most important, I guess, would be table prefix. So your query should look something like this: global $wpdb; $sql = “SELECT kategorie.id, ogloszenia.kategoria, klient_id “. “FROM {$wpdb->prefix}category kategorie “. “JOIN {$wpdb->prefix}ogloszenia_kupione ogloszenia ON (ogloszenia.id = kategorie.id)”; $results = $wpdb->get_results( $sql );
No, they are not the same. It is quite clear looking at the table names: term_id is the ID of a single term, whatever taxonomy it belongs to. The other information in the table term_taxonomy is related to the term – the slug, the title etc. term_taxonomy_id is the ID of the relationship between a … Read more
posts_join is only a part of the full SQL query, the table you’re joining to is referenced earlier in the query. You can see the full query with the posts_request filter. See the documentation for the rest of the query filters.
I don’t see where you define your custom table names. Please try: $wpdb->user_req = $wpdb->prefix . ‘user_req’; and $wpdb->user_req_admin = $wpdb->prefix . ‘user_req_admin’;
Your table names are wrong. note in your first query the use of $wpdb->posts to reference the posts table. however– this is a very simple query that can be done via the API rather than writing SQL queries from scratch. Use a new WP_Query instance instead.
The Problems You risk SQL injection, with your current setup: $wpdb->users.display_name LIKE ‘$ltr%’ The following could also be a problematic part in your SQL query: AND $wpdb->usermeta.meta_value = %artist% i.e. using = instead of LIKE. You’re also missing the quotes: %\”artist\”%, to exclude e.g. bartist or fartist 😉 But you don’t need to construct this … Read more
Using $wpdb to fetch posts with meta data