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

Select two sums with single get_var statement

$wpdb->get_var will do exactly what the name suggests– return a single value. So this: $sum = $wpdb->get_var(“select sum(first), sum(second) from sums_test where id > 1”); var_dump($sum); Will return the result of sum(first). The rest of the result is lost (though cached I believe). The method you want is get_row which will return a complete row … Read more

Only show upcoming event or current events

your are comparing time against wrong time string: change: ‘meta-value’ => date(‘Y-m-d’, strtotime(‘-6 hours’)), //value of “order-date” to this ‘value’ => date(‘m-d-Y’, strtotime(‘-6 hours’)), //value of “order-date” because your time string is in m-d-Y format and you are check against Y-m-d which is wrong. NOTE if above trick doesn’t work then i suggest you to … Read more

Query Custom Post Type posts by Keyword/url slug

You can use the name parameter in your arguments ex: <?php $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘name’ => ‘slug’ ); but this will only match the post with that same slug.

List all posts from past week grouped by sub-category

I would recommend that you use WP_Query for this one: $categories = get_categories( ‘child_of=83’ ); foreach ( $categories as $category ) { echo ‘<h3>’ . $category -> name . ‘</h3>’; echo ‘<ul>’; // create a WP_Query that retreives all posts from the specified // category which is older then 1 week $args = array( ‘cat’ … Read more

Alter a specific query on WordPress

You might be able to use the query filter hook See this WPSE answer Basically, you can do something like: add_filter( ‘query’, ‘your_filter_function’ ); function your_filter_function($query_sql) { // do something to $query_sql return $query_sql; } This will get called for every query, so you’ll need to test $query_sql to make sure it’s the query you … Read more

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