query post limits

The third parameter for add_filter is the priority in which the filter is executed, the forth is the number of parameters the function in the second parameter uses. The wpcodex_filter_main_search_post_limits function has an if that checks uses a couple of wordpress function to establish where in your page you are executing the code, in this … Read more

Custom taxonomy archive page problem

There are many choices here, and it is all up to you what you want to achieve and how you want to achieve it. My idea would be to use the templates available to avoid a lot of if else conditional statement. The Template Hiearchy makes provision for templates for terms, taxonomy-{$taxonomy}-{$term}.php, so you could … Read more

Do not show children of a category

Just use the parameter category__in of WP_Query – if you do this, then there is no need for cat and category__not_in. category__in does give you back results from the categor(y/ies) specified, but does not include results for the children of the specified categor(y/ies).

Get posts with multiple categories

category__and needs to be an array of category ID’s category__and (array) – use category id. You can modify your code to look like this $query = new WP_Query( array(‘category__and’ => array(12,32)));

wp_update_post question on array

wp_update_post expects ‘ID’ to be a single post ID, not an array. You will need to handle each post separately. Try: $post_ids = array( 1235, 1234, 1228, 1221, 1211, 1212, 1208, 1200 ); foreach($post_ids as $post_id) { $post = array( ‘ID’ => $post_id, ‘post_status’ => ‘pending’ ); wp_update_post($post); }

is_page Funtion for Posts ?

Remove the ! before is_page(). The function is_page() is built into WordPress and only tests if the post being viewed is a page or not. The ! stands for “not”, so if you take it out, the code will only return true on that part if it is a page.

How to get current post ID in functions.php

Try to get the post_id from the POST values instead of the global $post. function getcity(){ global $wpdb; if($_POST[‘state’]) { $id=$_POST[‘state’]; $postid = $_POST[‘post_id’]; $district = esc_html(get_post_meta($postid , ‘district ‘, true)); $result=$wpdb->get_results(“SELECT * FROM districts WHERE state_id=’$id'”); foreach($result as $row) { $district_name=$row->district_name; $district_id= $row->district_id; ?><option value=”<?php echo $district_id; ?>” <?php if($district == $district_id){echo ‘selected=”selected”‘;} ?>> … Read more

How to get links to the last N posts in a specific category?

First, there is no parameter named cat in get_posts. Use category instead to input comma separated category IDs or category_name to directly inserting category name. Second, in your code you have commented out the title of the post. Try this code. <?php $cat_id = get_cat_ID(‘category1’); $posts = get_posts( “category=$cat_id&posts_per_page=3” ); if ($posts) { foreach ($posts … Read more