How can I exclude only a specific sub category post from category display?

Ended up doing this (if the relevant post’s ID is, for example, 5): function filter_posts($query) { if ( $query->is_category() && $query->is_main_query()) { $this_category = get_queried_object(); if (0 == $this_category->parent) // Category has no parent $query->set(‘post__not_in’, array(‘5’)); } } add_action(‘pre_get_posts’, ‘filter_posts’);

calling pages instead of posts

This was already answered in the comment by Jack, but what you would do is add &post_type=page at the end of the WP_Query call. https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters Your revised query call: $my_query = new WP_Query(‘showposts=”.$show.”&orderby= ‘ . $orderby . ‘&order=” . $order . “&post_type=page’);

how to call recent post content in a loop ( only the content before read more tag)

for latest 5 post you can use this code: $args = array(‘post_type’=>’post’, ‘posts_per_page’=> 5); $query = new WP_Query($args); if($query->have_posts()): while($query->have_posts()):$query->the_post(); echo ‘<li>’; $content = get_the_excerpt(); //for featured image if(has_post_thumbnail()): the_post_thumbnail(); endif; print $content; echo ‘</li> ‘; endwhile; wp_reset_postdata(); endif; In case you want to change word count in excerpt use this action hook function. /** … Read more

Displaying 3 Category Posts differently

Possible you’ve forgotten to reset post with wp_reset_postdata function. You can use get_posts instead of new WP_Query: <?php foreach(get_posts($args) as $post) : ?> <div class=”post”> <a class=”post-link” href=”https://wordpress.stackexchange.com/questions/277736/<?= get_permalink($post->ID) ?>” target=”_blank”><?= $post->post_title; ?></a> </div> <?php endforeach; ?>

Add post id as body class in wordpress admin dashboard [duplicate]

Not sure to completely got your question, but if you are looking for a way to have in the editor the same classes you are using in the frontend, put an editor-style.css file in your child theme folder and fill it with the classes you need (i.e.:body). Then in your functions.php, add this line: add_editor_style(‘editor-style.css’);

WP_Query to get posts in a specific tag or has post_format

Try Below Code :- $query = new WP_Query(array( ‘posts_per_page’ => 2, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-link’ ) ), array( ‘taxonomy’ => ‘space’, ‘field’ => ‘term_id’, ‘terms’ => array(’16’), // 16 is the code for tag longform ‘operator’ => ‘IN’ ) ) ));