Posts – display all posts except a post by an ID

Couple of issues here IIRC, exclude should be an array of ID’s as exclude get passed to WP_Query as post_not_in You are defining arguments which you don’t use. You could have simply passed that to get_posts. Rememeber, all parameters in WP_Query is available as is to get_posts as get_posts uses WP_Query You can simply use … Read more

How to provide meta_key array to wp_query?

The WP_Query() custom field (i.e. meta) query can handle arrays for field values. You just need to add the compare key to your array: $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘post’, ‘meta_query’ => array ( array ( ‘key’ => ‘my_key’, ‘value’ => ‘target_value’, ‘compare’ => ‘IN’ ) ) ); $new_query = new WP_Query( … Read more

Display custom post type by custom taxonomy

The problem is in your tax_query terms parameter. Try: ‘tax_query’ => array( array( ‘taxonomy’ => ‘listings_tags’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug, ), ), And if you want posts from just basic, there’s no need for getting terms and loopin through. All you can do is WP_Query with tax_query terms parameter as ‘basic’.

Get the amount of posts on a current page

You can use the below to output the post amounts <?php $args = array( ‘post_type’ => ‘post’, ‘showposts’ => ’10’ ); $wp_query = new WP_Query($args); // amount of posts per on the page $post_number = $wp_query->post_count; // amount of posts across the post pages $post_number2 = $wp_query->found_posts; echo $post_number.'<br />’; echo $post_number2.'<br />’; while ( … Read more

WordPress website loads more posts than expected

The theme is most likely altering the main query via the pre_get_posts hook, chaning the posts_per_page argument to -1 for all posts, or another higher number. You can search your theme folder for pre_get_posts to see all the times this hook is used. A better solution would be to install the Query Monitor. With this … Read more

How to get post ID in a Page?

You should not use globals directly. There are some nice wrapper functions in the WordPress API. If you want to retrieve the ID of the current post or page just use get_the_ID(). Without any test … you could write the functionality in this way: $file_id = get_post_meta( get_the_ID(), ‘sound_s’, true ); $file_url = wp_get_attachment_url( $file_id … Read more