How to create a multidimensional array with multiple loops

I don’t think this is a restrict WordPress question, but you might try $args = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘work’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ); $data = array(‘work’ => array()); $loop = new WP_Query($args); if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post(); $id = $loop->post->ID; $attachments=array(); if(get_field(‘work’)): while(has_sub_field(‘work’)): $attachment_id = get_sub_field(‘image’); $caption … Read more

Put multiple custom loops on same page

Because you used query_posts your loop-land template is clobbering the main query. Don’t use query_posts. In loop-land do this instead: $land = new WP_Query($query_string . ‘&caller_get_posts=1&posts_per_page=9’); if($land->have_posts()) : while($land->have_posts()) : $land->the_post(); What happens is that query_posts overwrites the main Loop and you loop over that. When you get to the have_posts part of the second … Read more

get_the_ID not returning correct ID value

The array intialize of the variable $valid_post_id is incorrect. Change: <?$valid_post_id(‘1′,’2′,’3′,’4’);?> to <?php $valid_post_id = array(‘1′,’2′,’3′,’4’);?>

displaying recent comments outside loop without plugin

You can do that with get_comments. <?php $comments = get_comments(array( ‘number’ => 10, // 10 comments ‘status’ => ‘approve’, // only approved comments ‘post_status’ => ‘publish’, // only on published posts )); // do stuff with $comments You can see how the core itself does this in the recent comments widget.

How can I access specific posts brought back by query_posts?

Why not just use a counter and then conditional logic? $i = 0; while($loop->have_posts()) : $loop->the_post(); if($i === 0){ echo ‘<div class=”a”>’.other_stuff().'</div>’; } elseif($i === 1){ echo ‘<div class=”b”>’.other_stuff().'</div>’; } else { echo ‘<div class=”default”>’.other_stuff().'</div>’; } $i++; endwhile;

How to modify search.php to not show pages only show posts

The search template is way too late to change anything: The pages are searched already here, and your page numbers would be wrong. Do not alter the output, alter the query. Filter posts_search instead, and if there is a search term, filter posts_where_paged and remove the post type you don’t want to be searched. Sample … Read more

First article : single column; Other articles : 2 columns

Test and let me know: Put the following code into your index.php (or front-page.php): <?php if( have_posts() ) : ?> <div class=”col-full”> <?php for( $news = 0; $news < 1; $news++ ) { ?> <?php the_post(); ?> <h3 class=”news-title”><?php the_title(); ?></h3> <div class=”news-excerpt”><?php the_excerpt(); ?></div> <?php } ?> </div> <div class=”place-for-ad”></div> <?php // Start Two … Read more

Loop Problem: Displays same set of post for all categories

You are passing the same arguments to retrieve every set of posts. You have alter the arguments dynamically to reflect the current category. $categories = get_categories($catArgs); if($categories){ foreach($categories as $category) { $postArgs[‘cat’] = $category->cat_ID; $my_query = new WP_Query($postArgs); // … Untested, and I am away from my dev server but that should be pretty close. … Read more