Query custom post type in the loop

You are probably getting a rewrite conflict with the has_archive argument here: $args = array( ‘labels’ => $labels, ‘description’ => ‘Holds our services and service specific data’, ‘public’ => true, ‘menu_position’ => 5, ‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’ ), ‘has_archive’ => true, ); Set has_archive to false if you do not want the automatically … Read more

Two different conditions with a single WP_Query

So from my understanding: IF > User not Logged In – Show all ‘Public’ (meta) posts. ELSE IF > User Logged In – Show all ‘Public’ (meta) posts (from all users) AND all ‘Private’ (meta) posts from the current logged in user. I’ve run two queries below and combined the posts. It’s not without flaws, … Read more

Using global $post; to get featured image for custom post via WP_Query

$port_query->the_post(); should set the $post global. That isn’t the problem. The problem is that the you are trying to use $post before your secondary Loop runs (99% sure). You’ve hooked the bkg_featured_image() function to wp_head. wp_head runs in the header of the document, which, unless you are careful, will run before the other template code. … Read more

Set if condition with wp_nav_menu

No need to use conditional here to hide your nav menu when it is empty. Have a look at wp_nav_menu( $args );. It accepts the following arguments $defaults = array( ‘theme_location’ => ”, ‘menu’ => ”, ‘container’ => ‘div’, ‘container_class’ => ”, ‘container_id’ => ”, ‘menu_class’ => ‘menu’, ‘menu_id’ => ”, ‘echo’ => true, ‘fallback_cb’ … Read more

Get data of all posts of a query before pagination

If you want to accomplish it in a single query, hook pre_get_posts to query for all posts: function wpd_archive_all_posts( $query ){ if( $query->is_post_type_archive( ‘attractions’ ) && $query->is_main_query() ) $query->set( ‘posts_per_page’, -1 ); } add_action( ‘pre_get_posts’, ‘wpd_archive_all_posts’ ); Then paginate those results manually in the template: if( have_posts() ){ $posts_per_page = 10; $paged = ( get_query_var(‘paged’) … Read more

Single meta_query query using OR instead of AND in request’s WHERE statement

I believe the shortest and best approach is to (1) modify the query: function search_faqs_metadata($query) { if(!is_admin() && $query->is_main_query()) { if($query->is_search) { $query->set(‘meta_query’, array(array( ‘key’ => ‘_faqs’, ‘value’ => $query->query_vars[‘s’], ‘compare’ => ‘LIKE’ ))); } } } add_action(‘pre_get_posts’, ‘search_faqs_metadata’); and then (2) replace the AND with OR via the get_meta_sql filter: function change_meta_key_where_from_and_to_or($sql) { if(is_search()) … Read more

have_posts() execution failure

Your problem is the weird code at the top of the page. To understand what’s happening let me state a standard loop in pseudocode: if we still have posts to process while we still have posts to process mark this post as processed and move to the next one do things with it ( like … Read more