Display content of page template (get_page)

You seem to be confusing the database object that is a post/page, and the rendered output that is a post/page. The data contained in the wp_posts and wp_post_meta tables define the post object. A template file defines the rendered output when a given database object is queried. There are three types of queries: the default, … Read more

How do I Use Multiple Loops with WP_Query?

As Toscho mentionned above, you didn’t close your if and while. When in doubt, indent your codes to avoid confusion. $my_query = new WP_Query( $args ); if ($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post(); endwhile; endif; wp_reset_postdata(); /* The 2nd Query (without global var) */ $query2 = new WP_Query( $args2 ); // The 2nd Loop if ($query2->have_posts()) … Read more

How to filter posts that belong to a specific category only if that is the only category

You will need more than one query because before querying posts you have to know what posts to exclude. I personally don’t see anything bad in ‘cutoff’. This code should work properly: Update: It breaks pagination (see comments). <?php $category_to_filter = 11; while ( have_posts() ) : the_post(); $categories = get_the_category(); if( in_array($category_to_filter, $categories) && … Read more

How to display 7 most recent days of posts?

You can do all of this outside the template, via the pre_get_posts action and a filter on posts_where. The first function checks if it’s the main query and the home page, if so it applies a filter to the query’s posts_where clause. The posts_where function limits post selection to today’s date minus 7 days, then … Read more

Create a loop that gets pages with their template

The snippet from codex is a bit redundant in your case. You can achieve what you need, by using snippets like these: index.php $mainpage = get_page_by_title( ‘ROOT’ ); $the_query = new WP_Query( array( ‘post_parent’ => $mainpage->ID, ‘post_type’ => ‘page’, ) ); $index = 0; while ( $the_query->have_posts() ) : $the_query->the_post(); echo ‘<section class=”page’ . get_the_ID() … Read more

Loop through Custom Post Type, and then show children within each iteration

Placing the following code within the WP_Query loop works: <?php $parent_page_id = ( ‘0’ != $post->post_parent ? $post->post_parent : $post->ID ); $mypages = get_pages( array( ‘child_of’ => $parent_page_id, ‘post_type’ => ‘programs’ ) ); foreach( $mypages as $page ) { $content = $page->post_content; if ( ! $content ) // Check for empty page continue; $content = … Read more

Customize WooCommerce Product Images (Placement and size) [closed]

The file responsible for generating the sidebar cart is mini-cart.php and is located in woocommerce/templates/cart/mini-cart.php What you do is you copy that file and paste it into YOURTHEMEFOLDER/woocommerce/cart/mini-cart.php Open up that file and edit line 40 where it contains <?php echo $_product->get_image(); ?>` Change that to <?php echo $_product->get_image( array( 50, 80 ) ); ?> … Read more