Show All Posts Insert Edit Link

See if this doesn’t do it: First, the callback for that Ajax search (the wp_link_query method in wp-includes/class-wp-editor.php) suppresses the normal filters. We have to turn them back on for this particular query. function undo_suppress($qry) { global $_POST; if (isset($_POST[‘action’]) && ‘wp-link-ajax’ == $_POST[‘action’]) { $qry->set(‘suppress_filters’,false); } } add_action(‘pre_get_posts’,’undo_suppress’); Now we can use the posts_where … Read more

How to tell if $query_var isset?

use the indentical comparison operator: if(get_query_var(‘cls’) !== ” && get_query_var(‘ch’) !== ”) { mcs_textbook_chapter($dialect, $cls, $ch); } elseif(get_query_var(‘cls’) !== ”) { mcs_textbook_chapter($dialect, $cls); } else { mcs_textbook($dialect); }

Show recent products first but “sold out last” in query

If we only have two stock statuses, namely outofstock and instock, we can very easily achieve sorting with pre_get_posts add_action( ‘pre_get_posts’, function ( $q ) { if ( !is_admin() // Target only front end && $q->is_main_query() // Only target the main query && $q->is_post_type_archive() // Change to suite your needs ) { $q->set( ‘meta_key’, ‘_stock_status’ … Read more

wp remove query

I’m assuming you’re talking about this piece of maintenance code right here: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/post.php#L419 Indeed, the code calls on lower level functionality of $wpdb, which doesn’t contain too many hooks, only one in fact, query. http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/wp-db.php#L1061 So, in order to return an empty result set you’ll have to come up with a no-operation type of query, … Read more

Insert html after certain amount of posts?

You could use the following and it should do exactly what you want by checking the value of $loop->current_post. <?php $loop = new WP_Query( array( ‘post_type’ => ‘work’,’posts_per_page’ => ‘-1’ ) ); ?> <ul id=”carousel”> <li> <ul class=”inner-items”> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php if( $loop->current_post && !($loop->current_post % 6) ) : … Read more

How to get category link without a database query

It’s down to how you’re using get_term_link() – since you’re passing a slug, WordPress can’t locate the term in it’s internal cache (terms are indexed by ID), so it grabs it directly from the db. To use the cache, pass the ID. Better yet, pass just the object: get_term_link( $category ); // No need for … Read more

Different Main Navigation per category

You could set this in your theme using conditionals. Create a separate menu for each category using the WordPress menu feature (Appearances > Menus). Then in your theme, where you want the menu to display, determine which menu to display using the is_category(‘category-slug’) and/or in_category(‘category-slug’) conditionals and the wp_nav_menu function (http://codex.wordpress.org/Function_Reference/wp_nav_menu). For instance: <?php if(is_category(‘first-category’) … Read more