loop inside the foreach

Finally, I figure it out. It seems that the get_posts and query_posts accept different arguments, when I use the get_posts I can setup the arguments like this: get_posts(array( “category” => $cate->term_id, “numberposts” => 12 )); While when I use query_posts I have change that to: query_posts(array( “cat” => $cate->term_id, “numberposts” => 12 )); Notice the … Read more

How to loop through yoast primary categories? [closed]

Managed to sort it, the primary category is added as post meta to the post, therefore you can pass through the following arguments: ‘meta_key’ => ‘_yoast_wpseo_primary_news-category’, ‘meta_value’ => 1179, Note: your meta key will be different since this is a custom taxonomy that I have set up, if you print the get_post_meta for your posts, … Read more

WordPress Alphabetical Sort Loop Issue

I would approach this a bit differently. You’re outputting all pages, so I would just get them all in one go. You can then iterate over each letter, run the loop, and compare the current letter with the page title to see if it matches. $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘orderby’ … Read more

I need to display all post in onepage

You can use WP_Query <?php $args = array( “post_type’ => ‘faq’, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘posts_per_page’ => -1 ); $query = new WP_Query( $args ); if( $query->have_posts() ): ?> <ul id=”myUL” class=”margb-40″> <?php while( $query->have_posts() ): $query->the_post(); ?> //content <?php endwhile; ?> </ul> <?php wp_reset_postdata(); endif;

add offset to archive page

I am not sure what exactly you are trying to do. Here is an example using offset. For a category the first post is being displayed and that can have a unique HTML structure/layout. Then the remaining posts are shown but the search omits the first results and it offset by one item. Does this … Read more

Using variable in WordPress loop as criteria

You need an IN comparison and array if you want to match multiple values. array ( ‘key’ => ‘sale_or_rent’, ‘compare’ => ‘IN’, ‘value’ => array(‘Sale’, ‘Rent’), ),

WordPress shortcode in content, output in sidebar?

If you wanna show the content in sidebar if current post content has the shortcode then you should try has_shortcode function. Here is a demonstration- $content = get_the_content(); if( has_shortcode( $content, ‘your-shortcode’ ) ) { // The content has a [your-shortcode] short code, so this check returned true. } Hope it helps.

Posts not showing

I think you need to check if you are in the properties post type archive before to manipulate the query, so it doesn’t affect to other archives. Also, you need to check if the actual $query is the main query, so other queries are not affected (the function is_main_query() does a different thing; it doesn’t … Read more