Unable to paginate a custom page query

The problem was in the same name for category slug “categories” and the same for the custom page that was holding all categories with the same name “categories”. I have solved that by changing categories slug (in permalinks settings) to singular “category” and I have left custom page as plural “categories”. If somebody know about … Read more

specific post is not excluded from the loop

You’re just off by one letter it seems. post__not_in => array(118) Post & Page Parameters You can also try adding an if statement, such as: if($post->ID != 118) : … run rest of code Though not optimal, without seeing the rest of your template I can’t be certain. Additional Edit: <?php $loop = new WP_Query(array( … Read more

Widget only in first post

Assuming you are trying to add content only to the first post in the loop, a static variable should do it: function pietergoosen_insert_content_filter( $content ) { static $first; $first = (!isset($first)) ? true : false; if (true == $first) { ob_start(); $sidebar = dynamic_sidebar(‘sidebar-19’); $new_content = ob_get_clean(); if ( ! is_admin() ) { return pietergoosen_insert_content( … Read more

Ignore image urls in wp_query search

You just need to add post_type argument like this: $wp_query = new WP_Query( array( ‘s’ => $_GET[‘s’], ‘post_type’ => array( ‘post’, /* add more post types if need be */ ), ) ); Read the codex article about WP_Query class for more information.

Query multiple meta key values for template

No idea why you’re using clunky custom SQL, use a meta query instead. $pageposts = get_posts( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘_wp_page_template’, ‘value’ => array( ‘templates/front-page-excerpt.php’, ‘templates/front-page.php’, ) ) ), ) );

using nav menu id’s

If you have posts and pages then page_id isn’t the correct parameter. You should probably use post__in. See WP_Query Parameters. Additionally, post__in accepts an array, whereas you have a string, so you’ll need to use PHP to explode the string into an array. This is untested, but I think it should do it: $ids=”7,43,20,22,16,1051,18,26,9,24,28,10523″; $ids … Read more

posts_per_page is not working

You could try pre_get_posts in your functions file as another option. add_action( ‘pre_get_posts’, ‘limit_cpt_tax_term_posts’ ); function limit_cpt_tax_term_posts( $query ) { if( $query->is_main_query() && !is_admin() && is_tax( ‘cs_album_categories_tax’, ‘bollywood-songs’ ) ) { $query->set( ‘posts_per_page’, ‘8’ ); } } You may also find this solution useful as it includes another option and explanation relating to taxonomy terms … Read more

Randomly select one of last 3 posts

$args=array( ‘orderby’ => ‘rand’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 3, ‘offset’ => $offset, ); $q = new WP_Query($args); if($q->post_count>0){ $random_post = $q->posts[mt_rand(0,2)]; } also, just a little note, ORDER BY RAND() is pretty bad for performance