Making certain categories of CPT not publicly queryable

Sounds like you really just need a filter on pre_get_posts to remove the unwanted terms. Something like this, but I am not sure I understand all the conditions you need so think of it as proof of concept only. function exclude_terms_wpse_117242($qry) { if (is_user_logged_in()) { $tq = array( array( ‘taxonomy’ => ‘your_tax’, ‘field’ => ‘id’, … 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

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