Using external DB within wordpress

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

Combine posts and postmeta

$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;

Using $wpdb to insert data into a table

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

How to pull data from a table using wpdb?

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 );

Advanced WordPress SQL Query

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()…

How to get specific table by current user login

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)