Exclude category and post from loop in custom category.php

Here is a correct way: <div id=”category__product-grid” class=”row”> <?php query_posts( array( ‘cat’ => array(6,-45), ‘post__not_in’ => array(-598), ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ) ); ?> <?php // The Loop while ( have_posts() ) : the_post(); ?> <div class=”col-md-4 col-product-item”> <a href=”https://wordpress.stackexchange.com/questions/321415/<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><div class=”cat__featured-img”><?php the_post_thumbnail(); ?></div></a> <h2><a href=”https://wordpress.stackexchange.com/questions/321415/<?php the_permalink() ?>” … Read more

Create a list of pages excluding children of selected page

//Create an array containing the IDs of pages that are children of page ID XXX $args = array( ‘post_type’ => ‘page’, ‘post_parent’ => XXX, ‘fields’ => ‘ids’, ‘posts_per_page’ => -1, ); $qry = new WP_Query($args); //Convert the array into a string $string = implode(‘, ‘, $qry->posts); //Display the list of IDs – for testing purposes. … Read more

Skip latest 3 posts from loop

You can use the pre_get_posts action to alter your main query. The codex has a note that using the action might break pagination. Have a look at this old question and answer, Changing Posts Per Page and offset with pre_get_posts It has code examples for using the pre_get_posts and how to handle the pagination problem … Read more

Only Show Excerpt After First 3 Posts

You could add a count variable and count how many times the page has looped and only show the excerpt if the count is 3 or greater.: <?php $Count = 0; ?> <div class=”content-block-archive”> <div class=”content-block-archive-thumbnail”> <a href=”https://wordpress.stackexchange.com/questions/343700/<?php the_permalink(); ?>”><?php echo get_the_post_thumbnail($post_id, ‘large’, array(‘class’ => ‘alignleft’)); ?></a> </div> <div class=”content-block-archive-meta”> <h2 class=”content-block-archive-title”><a href=”https://wordpress.stackexchange.com/questions/343700/<?php the_permalink(); ?>”><?php … Read more

Exclude a category and post_type from wp_query

You can use simply category__not_in parameter to exclude one or several categories from your result. The sample is like this: $query = new WP_Query( array( ‘category__not_in’ => array( 2, 6 ) ) ); To see list of available parameters and complete example, see documentation of WP_Query in developer.wordpress.org I hope you can use it.

How to get an array of pages ID by some page’s slug and all its children pages in get_posts() function?

You can use get_page_by_path() to get a Page’s WP_Post object using its slug (ie, its path), and then use that object to then get the array of child page IDs using get_children(). // First we’ll create the list of posts (pages) to exclude. $exclude = array(); $parent_page_obj = get_page_by_path( ‘abc’ ); if ( ! empty( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)