WordPress Search Filter Only for Page with Child of Child of Child of Child of Child

You can probably do something like this. It’s probably less efficient, but should find all descendants of a given page rather than just direct children. function find_descendants($post_id) { $descendant_ids = array(); $pages = get_pages(“child_of=$post_id”); foreach ($pages as $page) { array_push($descendant_ids, $page->ID); } return $descendant_ids; } function SearchFilter($query) { if ($query->is_search) { $query->set ( ‘post__in’, find_descendants(21) … Read more

How to Get All Posts but the Private ones?

I believe get_posts returns all published (no-private posts) but does display password protected posts. In fact, by default, the standard WP_Query loop does this as well. So by default, private posts shouldn’t appear. If you wanted to display private posts for those logged in, and not those who are logged out, you could use the … Read more

Counter code for paginated category pages in wordpress

Yes, of course it starts again at 1. You’ve initialized the counter to 1 on each page load. If you were writing a custom loop you’d do this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; If normal WordPress pagination mechanisms are working on your page that should work for you too. That will number your … Read more

Insert custom div between posts

You can check your position within the loop using the current_post var of the $wp_query object, and insert markup at a specific spot or at some interval. A simple example: while( have_posts() ): the_post(); the_title(); the_excerpt(); // if current_post is 1, insert the div // note that current_post starts at 0, // so this will … Read more

how could I get the pagination as I want to when query posts using get_posts function

Use paginate_links. It is meant to do pretty much just that. Plus, the ordinary pagination functions like next_posts_link (which I think you want instead of next_post_link) do not work reliably with custom queries, but next_post_link and previous_post_link are equally or more troublesome with custom queries. With paginate_links you need to pass quite a bit of … Read more

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