WordPress choose wrong database

In case someone is interested. I made it work. I made a plugin and in the main php-file I wrote this. <?php function ir_load(){ include_once(ABSPATH . ‘load.php’); } function db_fix_login(){ global $wpdb; $wpdb->select(DB_NAME); } add_action(“wp_head”,”db_fix_login”, 0); ir_load(); db_fix_login(); ?> The ir_load() contains the database connection to my database. I made it a function in case … Read more

Converting the_content string to an array?

Filter ‘img_caption_shortcode’. You get three arguments: an empty string, the attributes (including the attachment id), and the caption content. If you return anything but an empty string WordPress will print your return value instead of its own code. See wp-includes/media.php for details. Another option: hijack the caption handlers and create your own output or change … Read more

What is wrong with this wpdb update?

you’re creating the $data and $where values as strings, not arrays. this: $data = “array( ‘somecol’ => ‘”.$newstr.”‘ )”; $where = “array( ‘id’ => “.$defid.” )”; should be: $data = array( ‘somecol’ => $newstr ); $where = array( ‘id’ => $defid );

Correct way to perform non-cacheable DB query

I am not completely sure what you are talking about so I will mention the possibilities that come to mind. Maybe this… // Keep track of the last query for debug.. $this->last_query = $query; http://core.trac.wordpress.org/browser/tags/3.5.2/wp-includes/wp-db.php#L1195 … is what you are talking about. If so, your code just runs the flush method which resets $wpdb properties … Read more

using $wpdb to get custom post type with term

Any suggestions on how to get the title of the first custom post type of ‘property’ with the term ‘Locked’ in the taxonomy ‘status’? $args = array( ‘post_type’ => ‘property’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘status’, ‘field’ => ‘slug’, ‘terms’ => ‘locked’ ) ) ); $your_query = new WP_Query( $args ); while ( $your_query->have_posts() … Read more

Search Everything & WP 3.7 update issues [closed]

Thanks to @Pat J i removed the syntax that was causing me problems. For those who are interested, inside the Search Everything plugin, on line 198 – 221 there is the following function: function se_search_default() { global $wpdb; $n = ( isset( $this->query_instance->query_vars[‘exact’] ) && $this->query_instance->query_vars[‘exact’] ) ? ” : ‘%’; $search=””; $seperator=””; $terms = … Read more

Is it necessary to escape LIKE term in WP_User_Query?

like_escape() only escapes % and _ characters. The entire function looks like this: function like_escape($text) { return str_replace(array(“%”, “_”), array(“\\%”, “\\_”), $text); } Quoting from the Codex, esc_attr() Encodes the <, >, &, ” and ‘ (less than, greater than, ampersand, double quote and single quote) characters. Will never double encode entities. Always use when … Read more

Optimizing Query used for a Shortcode

I see a few things that you might try to shortcut things: Currently a Multisite network only allows one site ID, according to the Codex page for $wpdb->siteid. Also, the site ID is defined in your wp-config.php file as a constant, BLOG_ID_CURRENT_SITE. So any reference to $wpdb->siteid can be replaced by BLOG_ID_CURRENT_SITE. Look into the … Read more

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