Custom post type archive pagination query issue
Custom post type archive pagination query issue
Custom post type archive pagination query issue
Run first query las 10 posts, than use array_rand PHP function on posts array: $args = array( ‘posts_per_page’ => 10, ‘post__not_in’ =>array( $post->ID ), ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’ ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { if ( $query->post_count > 4 ) { $query->posts = array_rand( $query->posts, 4 ); … Read more
Pagination on static Posts page
Replace your ajax code with this code. I didn’t check it but i think it should we working. The whole html part is convert into string so that it will send via ajax response. <?php global $post; $data = filter_var_array($_POST, FILTER_SANITIZE_SPECIAL_CHARS); if ($data[‘action’] == “timeline_load”) { $post = null; $args = array( ‘post_type’ => ‘timeline’, … Read more
There are several ways to achieve this, depending on the permalink structure of your posts. Assuming the post slug is part of the permalink structure, you can get the post slug from the post URL and fetch the corresponding post by using WP_Query with the name-parameter. Let’s assume the structure of the URLs is http://example.com/{post_slug}/. … Read more
You should use an object cache, it will definitely speed up the get_post_meta queries as they will be cached when doing the initial WP_Query (get_posts). I recommend testing with APC cache, using the APC Object Cache Backend : https://wordpress.org/plugins/apc/ Just drop the file in your wp-content folder and make sure you have APC extension available.
Take a closer look at the date parameters; you’ll need to enter an integer (number), not a string (text). Simply get rid of the single quotes to make it work: $args = array( ‘post_type’ => ‘job’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘location’, ‘terms’ => ‘dallas’, ‘field’ => ‘slug’ ) ), ‘date_query’ => array( array( … Read more
How to query custom post types with mixed AND & OR statements for custom fields
@user6394526 is right… you cant really exlude post types but you can declare which post types you want to retrieve… See his answer for an example. The second option which is less preffered (since is would query all posts, even the ones you dont need!) is to check for post type and ignore the one … Read more
You should probably provide different default if empty string is indistinguishable from your value. $myvar = get_query_var( ‘myvar1’, false ); if ( false !== $myvar ) { // stuff }