Query only displays one page_id

The p parameter accepts a single integer value, not a string or array of integers. You would want to use the post__in parameter which allows for an array of post id’s. Just a few notes here: You will need to check if you actually have a valid array of post ID’s before passing it to … Read more

How is WordPress changing the content markup?

WordPress runs a filter on the content to automatically add paragraphs: wpautop. You can remove the filter from all your post’s content if you like: remove_filter(‘the_content’,’wpautop’); Alternatively, you can check out the Disabler plugin which can do this for you. If you want to remove the filter from particular post(s) you can do: add_filter(‘the_content’,’maybe_remove_wpautop’,9); function … Read more

Dividing the loop to style post differently

You don’t need to alter the code for different formatting, you can simply use the :first-child pseudoclass in css. The foreach loop will, presumably, generate similar blocks of code, structured like this: <div class=”all-my-posts”> <article class=”my-slider-post”> … </article> <article ..> </article> … </div> Now you can simply addres the first <article> block with css like … Read more

Exclude page from loop results

You need the WP_Query documentation. WP_Query is very powerful, and you can do a lot with it 🙂 In your case, I don’t think exclude is a valid parameter. What you’re probably looking for is this: $query->set( ‘post__not_in’, array( 34 ) ); Here’s the Post & Page Parameters section of the documentation, which covers this … Read more

WP_Query with one category in args shows other categories

Tried your code in a simple page and work correctly. Have you set the “Blog” page as posts page within the “Settings > Reading”? Because in this case the correct code that the cms will load is home.php or index.php according to the template hierarchy https://developer.wordpress.org/files/2014/10/template-hierarchy.png

How do I sort this custom list of sticky posts

This should do the trick: $sticky = get_option( ‘sticky_posts’ ); $args = array( ‘posts_per_page’ => -1, ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1 ); $query = new WP_Query( $args ); $ids_by_category = array(); while ($query->have_posts()) { $query->the_post(); $post_categories = wp_get_post_categories(get_the_ID()); foreach($post_categories as $c){ $cat = get_category($c); $ids_by_category[$cat->slug][] = get_the_ID(); } } // sort by key ksort($ids_by_category); … Read more