Category nicename inside loop in wordpress

You can use get_the_category inside the loop to get the category/ies a post is assigned to. To get a list of available member variables available, see get_categories. I would suggest to target the first category only, which will also be the parent category if the post is assigned to only one parent and some of … Read more

Altering “posts_per_page” for defaut loop

As Tom said, that will never work, as the main query have already executed. The only way to achieve that is to alter the main query before it is executed. There is a action hook for that, pre-get_posts and this is the correct method to alter the main query. Example: function wpse_custom_ppp( $query ) { … Read more

Problem with Front-Page.php loading recent posts

You have to reset every instance of a custom query, otherwise you will get unexpected output from any other query there after Simply use wp_reset_postdata() after every custom query. Example <?php $args = array( ‘numberposts’ => ‘1’, ‘meta_key’=>’_thumbnail_id’ ); $recent_posts = wp_get_recent_posts( $args ); foreach($recent_posts as $post) : ?> <?php get_template_part( ‘content’, ” ); ?> … Read more

wp-query, pull children of parent page

If it’s a child page, the post_parent will be a non-zero value, so you could check for that: if( 0 == $post->post_parent ){ // no parent, get children of this page $childargs[‘post_parent’] = $post->ID; } else { // has parent, get children of parent page $childargs[‘post_parent’] = $post->post_parent; } This is assuming your child pages … Read more

Multiple instances of Featured Image Thumbnail As A Background On Homepage

Solution was to remove the style tag and and write the background styling right into the .featured_box div. Thank you to @ckhicks on Twitter for the solution, and thank you everyone else for trying to help out too <3 <?php $background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), ‘full’ ); ?> <a href=”https://wordpress.stackexchange.com/questions/160701/<?php the_permalink(); ?>”><div class=”featured_box” style=”background: … Read more

CPT while loop not working

Your post type is all wrong. Custom post type names cannot contain spaces or camelcase, also names should not contain special characters. Custom post type names, and for that matter, custom taxonomy names should be all lowercase letters, and names must only be separated by underscores (_) Have a look at the $post_type parameter in … Read more

Show related posts based of current ACF field name in a single page post (a loop within loop)

You don’t have a meta_value in your query. From your code I can’t tell what you’re doing with the meta values but you should be able to do this: // Store this BEFORE you go into the second loop. $category = get_field(‘category’); // The arguments for the second loop ‘post_type’ => ‘case-studies’, ‘showposts’ => 3, … Read more