Only display post if published in last 24 hours?

As birgire said date query is an array of arrays May be this solves your problemo. $args = array( ‘post_type’ => ‘surf_reports’, ‘posts_per_page’ => ‘1’, ‘category_name’ => $cat (this is pulled dynamically in my template), ‘date_query’ => array( array( ‘after’ => ’24 hours ago’ ) ) );

Query Posts by Custom Field

You can achive this using WP Query with meta_query argument as following. $args = array ( ‘post_type’ => array( ‘post’ ), // YOUR POST TYPE ‘meta_query’ => array( array( ‘key’ => ‘country’, ‘value’ => $your_country, // THE COUNTRY TO SEARCH ‘compare’ => ‘LIKE’, // TO SEARCH THIS COUNTRY IN YOUR COMMA SEPERATED STRING ‘type’ => … Read more

How to alter local query, not main query [duplicate]

One of the easier ways to do this is to just add the filter before your query and remove it after: add_filter( ‘posts_orderby’, ‘filter_function’ ); $something = new WP_Query( $args ); remove_filter( ‘posts_orderby’, ‘filter_function’ ); Then you can just add your function into functions.php as normal: /** * The below function filters something * Added … Read more

How to display Related Posts based on number of taxonomy terms matched

Let’s split the problem up in three bits: retrieving the related posts from the database, sorting them and displaying the result. Post retrieval This is possible using the taxonomy parameters offered in WP_Query. Let’s first retrieve the category of the current post and find their IDs: $categories = get_the_terms( get_the_ID(), ‘news-category’ ); foreach ( $categories … Read more

WordPress theme options error

First, change your code into the following: $value = get_option( ‘mytheme_value’ ); query_posts ( “meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value={$value}”); When you use single quotation marks, php isn’t parsed in the string, and functions (like get_option) will never be called from within a string. Therefore, call the function get_option first, and put the value in a double quoted string (which … Read more

How to show more post at a given category?

put this code in functions.php : function change_numberposts( $query ) { // Only modify the main query if( $query->is_main_query() ){ // Home page if ( $query->is_home() ) { $query->set( ‘posts_per_page’, 6 ); } // Category 21 if ( $query->is_category( 21 ) ) { // parameter for is_category may be Category ID, Category Title, Category Slug … Read more

WP_Query – Object manipulation vs WordPress functions

All 3 of these could do the same thing, it’s just a matter of how you want to use them. the_title() calls get_the_title() which gets the title by $post->post_title. View the_title() Source on Trac View get_the_title() Source on Trac Personally, I would never use choice 3 as from a readability stand point it’s not the … Read more