Accessing two databases wordpress

When enhancing WordPress functionality, always use the theme’s functions.php file (located, generally, in {WP root}/wp-content/themes/{your theme}/functions.php), or put your code into a plugin. The rules for hacking core code are similar to the rules for optimization. Don’t do it. (for experts only) Don’t do it yet.

Counting posts with argument without retrieving the posts

Here’s one thing you could do. Create a WP_Query object but only include ids: $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘books’, ‘s’ => $s, ‘fields’ => ‘ids’, ); $query = new WP_Query( $args ); $post_counts = $query->post_count; wp_reset_postdata(); By using fields => ids you’re only returning the IDs. Also, WP_Query already does a … Read more

Object method calling for global $wpdb in header.php

I think the problem might lie in: $wpdbinfo = $wpdb->get_results(“SELECT * FROM bo_mytable WHERE id=3”); $wpdb->get_results() returns an array of objects, yet you are referencing a property on $wpdbinfo (->nameinfo). You’ll either want to loop through the $wpdbinfo array, or if you’re certain you’ll get only a single record (possibly a safe assumption if id … Read more

WordPress SQL Issue not returning correct reselts

Here is my answer in code form: <?php // Customer Details $args = array( ‘blog_id’ => $GLOBALS[‘blog_id’], ‘role’ => ‘customer’, ‘meta_key’ => ‘last_name’, ‘meta_value’ => ”, ‘meta_compare’ => ”, ‘meta_query’ => array(), ‘date_query’ => array(), ‘include’ => array(), ‘exclude’ => array(), ‘orderby’ => ‘last_name’, ‘order’ => ‘ASC’, ‘offset’ => ”, ‘search’ => ”, ‘number’ => … Read more

$wpdb not being defined in function: Fatal error: Call to a member function query() on a non-object

Okay, new solution. First off, I’d recommend making the link a submit button and making the name something unique: <submit name ‘del_gallery’ /> Then in the code of your admin page: include ‘ga-functions.php’; //checks to see if certain button was pressed if(isset($_REQUEST[‘del_gallery’] && isset($_GET[‘gallery_id’]) ) { $gallery_id = $_GET[‘gallery_id’]; delete_gallery($gallery_id); wp_redirect( $_SERVER[‘HTTP_REFERER’] ); exit(); }

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