WPDB delivers wrong results from complex queries
WPDB delivers wrong results from complex queries
WPDB delivers wrong results from complex queries
1) If all output will happen in that one template, I don’t see why you can’t do everything in the template. How it’s organized is really up to you. 2) If the table is in the WordPress database, it certainly simplifies things, you won’t have to create a connection to another database. 3) It’s up … Read more
$args = array( ‘post_type’ => ‘my_custom_post_type’, ‘meta_query’ => array( array( ‘key’ => ‘name_of_field_with_featured_as_value’, ‘value’ => ‘featured’, ‘compare’ => ‘=’, ), ), ); $query = new WP_Query($args); if($query->have_posts()) : //usual loop code but with $query as above, note that post related functions are called as usual, e.g. simply the_title(), not $query->the_title() endif;
If i understand well, users will update their datas in front-office, and you need to save datas in your custom table. I think you must check on wp_ajax process which will allow you to post datas in JS to a WP_ajax handler. This handler will be a PHP function, (can be written in your theme’s … Read more
First, you want to use the global $wpdb variable. global $wbdp; Then set up your query. Make it a separate variable so you can output it and check for syntax errors. $my_query = $wpdb->prepare( /* SQL query here */ ); Then execute the query. $results = $wpdb->get_results( $my_query );
How to display specific data from custom database table in WordPress
In WP, you rarely need to “write SQL queries”, unless you work with custom tables, instead use its API… WP_User_Query will join for you all meta data attached to each user and return to you plain user objects, so why not use it instead? Also, see get_user_meta()…
Note that you may need to use WPDB::prepare() to prevent against SQL injections. Although, it might be arguable in your specific case… // If the query does not work, ensure the table name is correct… $table = $wpdb->prefix . ‘SaveContactForm7_1’; $reservations = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM $table WHERE user = %s”, $username ) ); … Read more
About your specific Problem? maybe you should have a look at your permalink settings. index.php/students doesn’t look right. The other thing: Why would you want to insert data into the database by using wpdb with data that is submitted from the frontend? The security risk is monumental, and if you don’t exactly know what you … Read more
WHERE NOT IN is what you need. $sql = “INSERT INTO trip_rate (id, trip, rating, r_name, email, title, review) SELECT ”, ‘$trip’, ‘$rating’, ‘$name’, ‘$email’, ‘$title’, ‘$review’ WHERE (trip_rate.email) NOT IN ( SELECT email FROM trip_rate WHERE email=”$email” AND trip=’$trip’)”;