How to query posts by month based on date custom field?

It is not clear what you’re using as a comparison, but WP Query supports meta query comparisons and even has a DATE type. For example: $query = new WP_Query( array( ‘post_type’ => ‘attraction’, ‘meta_key’ => ‘attraction_date’, ‘meta_value’ => ’10’, ‘meta_compare’ => ‘LIKE’, ‘type’ => ‘DATE’ ) ); Using 10 is not going to get you … Read more

Display latest post from WordPress Featured Category that is also in X,Y,or Z categories

Maybe this could help and should return any post either in 2, 3 or 4 category AND in categoery 1 : query_posts( array( ‘cat’ => array(2,3,4), ‘category__and’ => 1, ‘posts_per_page’ => 1, ‘orderby’ => ‘title’, ‘order’ => ‘DESC’ ) ); (from codex http://codex.wordpress.org/Function_Reference/query_posts) Not quite sure, haven’t tested it.

Best Query for blog posts

Do the following: Create a blank page with the name “Blog” or “News” or whatever you like to call it. Go to Settings -> Reading and select A static page from Front page displays section. Choose your front-page from the Front page dropdown box, and your blog page (the page you created in step 1) … Read more

Searching with Multiple (Parallel) Criteria on Custom Fields?

have a look at WP_Query(); and use meta_query / tax_query arguments $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘color’, ‘value’ => ‘blue’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘price’, ‘value’ => array( 20, 100 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) ) ); $query = new WP_Query( … Read more

create a link to a random post within the current category

I think it’s better to use get_posts function. You can change the number of posts that you want. I set the category id if you’re in a category page. <?php rewind_posts() ; $args = array( ‘numberposts’ => 1, ‘orderby’ => ‘rand’) ; $exclude_posts = array() ; if ( have_posts() ) { while ( have_posts() ) … Read more

How to add a Variable to post query

I’m not sure if is this that you need, but try to “explode” it… <?php // Headlines variable can control admin area // Does this return the string “2,3,4,5” ??? $headlines = get_option(‘t_turmanset’); query_posts( array( ‘numberposts’ => 4, ‘post__in’ => explode(“,”, $headlines) ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); … Read more

Anyone know a php snippet for showing the first 200 characters of the most recent post?

WordPress has an inbuilt function called the_excerpt() which echoes an excerpt of the post content. By default an excerpt is 55 characters. You can set it to 200 like so: function your_excerpt_length( $length ) { return 200; } add_filter( ‘excerpt_length’, ‘your_excerpt_length’ ); This should go into your theme’s functions.php, ideally. EDIT: To manipulate the excerpt … Read more

Display upcoming events in the next 30 days by querying posts with timestamp in custom meta

I recently did exactly the same, you’ll have to use custom query: $date = time()-86400; /* today */ $querystr = ” SELECT $wpdb->posts.* FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->posts.post_status=”publish” AND $wpdb->postmeta.meta_key = ‘event_date’ AND $wpdb->postmeta.meta_value > ” . $date . ” ORDER BY $wpdb->postmeta.meta_value ASC “; $pageposts = $wpdb->get_results($querystr, OBJECT); foreach ($pageposts … Read more