Query custom post type custom meta key

Now i got this code and i works. function get_events( ) { $recurrence_ids = get_post_custom_values( ‘_recurrence_id’ ); $recurrence_id = $recurrence_ids[0]; $the_query_args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘event’, ‘meta_key’ => ‘_recurrence_id’, ‘meta_value’ => $recurrence_id ); $the_query = new WP_Query( $the_query_args ); if ( $the_query->have_posts() ) { $output=”<div class=”weitere-termine”>”; while ( $the_query->have_posts() ) { $the_query->the_post(); … Read more

Exclude post from wp_query based on custom field boolean

Excluding things in queries is extremely expensive, but also avoidable. What’s more, filtering posts by their post meta values is also super expensive. That query would get exponentially slower as the post count rises. Instead you can avoid this completely by telling it what you do want, not what you don’t want. So instead of … Read more

pre_user_query vs pre_get_posts

The pre_get_posts function is a simple query modifier for general “post” queries. If you’re looking to modify the SQL directly for these query I suggest using the post_clauses hook. This hook passes an array of SQL clauses such as: $sql[‘where’] and sql[‘join’] Here you can inject your own custom SQL into the specific clauses. That … Read more

Category Page Displaying all Pages

Resolved using this: <div> <ul> <?php $current_category = get_queried_object(); ////getting current category $args = array( ‘post_type’ => ‘page’,// your post type, ‘orderby’ => ‘menu_order’, ‘order’ => ‘DESC’, ‘cat’ => $current_category->cat_ID // current category ID ); $the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post(); echo ‘<h2><a href=”‘.get_the_permalink().'”>’.get_the_title().'</a></h2>’; “<p>”.the_excerpt().”</p>”; endwhile; endif; ?> </ul> </div>

How to create a filter and add query params to all links

Assuming you mean $post->ID, you can use the post_link and post_type_link filters to append your query string. We’re using the add_query_arg() function to do this: /** * Modify the posts navigation WHERE clause * to include our acceptable post types * * @param String $post_link – Post URL * @param WP_Post $post – Current Post … Read more