Excluding pages in WP_query using ACF
Convert your string of IDs into a proper array: $exclude_ids = get_field( ‘exclude_pages’ ); $exclude_array = explode( “,”, $exclude_ids ); Then pass $exclude_array as the value for post__not_in.
Convert your string of IDs into a proper array: $exclude_ids = get_field( ‘exclude_pages’ ); $exclude_array = explode( “,”, $exclude_ids ); Then pass $exclude_array as the value for post__not_in.
Individual post. Meta_key, taxonomy or post status for separation?
get_page_by_title() source code shows it runs a single mysql query. You can streamline your two calls of the function to be just one query by writing a custom one: global $wpdb; $qry = “SELECT ID FROM $wpdb->posts WHERE (post_title = %s OR post_title = %s) AND post_status=”publish””; $sql = $wpdb->prepare($qry, ‘title1’, ‘title2’ ); $res = … Read more
This should work for you to exclude via ID: //replace the 3,8 with your page ids <?php $args=array( ‘post__not_in’ => array(3,8), ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ); query_posts($args); ?> If you want to exclude via page title you can do this <?php $exclude1 = get_page_by_title(‘Sample Page Title’); ?> <?php $exclude2 = get_page_by_title(‘Sample Page Title … Read more
I would suggest something like this: function exclude_widget_subcategories($args){ $all_categories = get_terms(‘category’, array(‘parent’ => 0, ‘fields’ => ‘ids’)); $exclude_categories = array(); foreach($all_categories as $category_id){ $children = get_term_children($category_id, ‘category’); if(count($children)!=0){ $exclude_categories[] = $category_id; } } $exclude = implode(“,”,$exclude_categories); // The IDs of the excluding categories $args[“exclude”] = $exclude; return $args; } add_filter(“widget_categories_args”,”exclude_widget_subcategories”); get_terms(‘category’, array(‘parent’ => 0, ‘fields’ … Read more
How do I exclude recent post from recent post php widget
The asker refused to post his solution as answer, so I took the liberty to get this question out of our growing Unanswered Questions list … <?php $logo = get_post_meta($post->ID, ‘_lm_comm_logo’, true); $map = get_post_meta($post->ID, ‘_lm_comm_map’, true); $args = array( ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, … Read more
I solved this by using this code function exclude_thumbnail_from_gallery($null, $attr) { if (!$thumbnail_ID = get_post_thumbnail_id()) return $null; // no point carrying on if no thumbnail ID // temporarily remove the filter, otherwise endless loop! remove_filter(‘post_gallery’, ‘exclude_thumbnail_from_gallery’); // pop in our excluded thumbnail if (!isset($attr[‘exclude’]) || empty($attr[‘exclude’])) $attr[‘exclude’] = array($thumbnail_ID); elseif (is_array($attr[‘exclude’])) $attr[‘exclude’][] = $thumbnail_ID; // … Read more
foreach ($categories as $individual_category) { if( $individual_category->term_id == 81 || $individual_category->term_id == 82 ) continue; $category_ids[] = $individual_category->term_id; } explanation: the above replaces: foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; i.e. the code jumps over the to be excluded categories.
In case it helps someone else, this was a much easier fix than I thought. I simply added the category ids to exclude to the query_posts argument, e.g., query_posts(“s=$s&cat=-415,-504&posts_per_page=-1”);