find posts with exactly 3/4 categories

Make sure you are providing correct category names into the function get_cat_ID(). <?php $catIDs = array(); $catIDs[] = get_cat_ID( ‘CategoryName1’ ); $catIDs[] = get_cat_ID( ‘CategoryName2’ ); $catIDs[] = get_cat_ID( ‘CategoryName3’ ); $my_query = new WP_Query( array( ‘category__and’ => $catIDs ) ); if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post(); ?> <li> <a href=”https://wordpress.stackexchange.com/questions/125935/<?php the_permalink(); … Read more

Cron jobs repeating themselves

The wp_schedule_single_event function in cron.php (http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/cron.php#L0) has a comment which says: // don’t schedule a duplicate if there’s already an identical event due in the next 10 minutes So I’d say that no it won’t trigger lots of calls for earlier in the day.

Listing all selected terms for custom taxonomies on a post

$args = array( ‘post_type’ => ‘inspirations’, ‘posts_per_page’ => 10 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $collections=””; foreach ( (array) wp_get_post_terms( get_the_ID(), ‘collections’) as $collection ) { if ( empty($collection->slug ) ) continue; $collections .= ‘ collection-‘ . sanitize_html_class($collection->slug, $collection->term_id); } echo ‘<div class=”inspirations-post ‘. $collections . ‘”>’; the_title(); … Read more

Route to custom file

This is just simple. First create a page and use slug for it as custom. And then rename you php file to page-custom.php and that would be it.

How do you get the docroot directory?

// server document directory $dir = $_SERVER[‘DOCUMENT_ROOT’]; // wordpress install directory $dir = ABSPATH; to include safely with wordpress add_action(‘plugins_loaded’, ‘load_a_file’); function load_a_file(){ if( is_admin() ){ $dir = $_SERVER[‘DOCUMENT_ROOT’]; include_once( $dir . ‘/file.php’ ); } }