How navigation works in custom loop within shortcode?

if you look at previous_posts_link() and next_posts_link() in source, you’ll see why they don’t work, they use the global $paged and $wp_query vars to format the links and determine whether or not they appear. you’ll have to roll your own pagination using the paged and max_num_pages vars in your custom query.

Query multiple post type and categories

The following code selects IDs of all posts type product and post, which belong to terms category-a or category-b, with taxonomy_01 and taxonomy_02, respectively. $args = [ ‘post_type’ => [‘product’,’post’], ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘tax_query’ => [ ‘relation’ => ‘OR’, [ ‘taxonomy’ => ‘taxonomy_01’, ‘field’ => ‘slug’, ‘terms’ => ‘category-a’, ‘include_children’ => false, … Read more

Dynamically Override Fancy Title – Part II

I finally got it. The final version of the function is: <?php // ACCOMODATION TITLE add_filter (‘presscore_get_page_title’,’netbooking_presscore_get_page_title’,10,1); function netbooking_presscore_get_page_title ( $title ) { if( is_page( ‘1057’ ) ){ $GLOBALS[“content”] = $content; // This reads input considering a default value in case of error $INPUT = function($param, $default, $prefix = true){ $key = $prefix ? ‘netbooking_structure_’.$param … Read more

Specific Loop For 2 Within Each

i use this code in my portfolio http://pocketapps.co/ <?php $args = array( //your argument code ); query_posts($args);?> <ul> <?php $ls=0; while ( have_posts() ) : the_post(); ?> <?php if($ls%2==0): echo ‘</li><li>’; endif; ?> <div class=”app”> //your code here </div> <?php $ls++; endwhile; wp_reset_query(); ?> </ul>

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

Is there any need to use both wp_reset_postdata and wp_reset_query together?

There’s no need to use them both. You should only use wp_reset_query(), if you modified query with query_posts() (which you should avoid). This function also call wp_reset_postdata() – http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/query.php#L95 So it’s better to use wp_reset_postdata() after running separate query.

Include both default and Custom Post Type in query modified inside pre_get_posts

As Kaiser mentioned, the post_type parameter can accept an array of post types. Updating the function to use is_main_query() to limit the filter to only the “main” query, the code would look like: add_action( ‘pre_get_posts’, ‘custom_post_author_archive’ ); function custom_post_author_archive( $query ) { if ( is_main_query() && is_author() ) { set_query_var( ‘post_type’, array(‘post’,’custom_post’) ); } }

Display two post types ordered by two custom fields

My old code was wrong, this is a good one, as I think: function add_custom_post_type_to_query( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘post_type’, array( ‘post’, ‘facebook_events’, ‘event’ ) ); $query->set( ‘meta_query’, array( ‘relation’ => ‘OR’, array( ‘key’ => ‘event_start_date’, //this is from facebook_events post type ‘value’ => date_i18n(“Y-m-d”), ‘compare’ => ‘>=’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)