exclude custom post type by meta key in wp_query

If you don’t use any other meta data, just add the following to your $args: ‘meta_key’ => ‘sold’, ‘meta_value’ => true, // or whatever it is you’re using here ‘meta_compare’ => ‘!=’, Otherwise, use a WP_Meta_Query: ‘meta_query’ => array( array( ‘key’ => ‘sold’, ‘value’ => true, // or whatever it is you’re using here ‘compare’ … Read more

Exclude pages with certain template from wp_list_pages

Daniel, exclude parameter doesn’t accept array. Use your code this way: $exclude = []; foreach(get_pages([‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => ‘page-templates/page-noindex.php’]) as $page) { $exclude[] = $page->post_id; } $args = array( ‘exclude’ => implode(“,”, $exclude), ‘title_li’ => ”, ‘sort_column’ => ‘menu_order, post_title’, ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’ ); wp_list_pages($args); I think you can refactor it … Read more

Filter keywords from search query

If I understand you correctly you’re not looking for the wp_search_stopwords filter type of solution. So here’s a modification of the great answer by @kaiser that you referred to: /** * Exclude array of words from all search queries in the front-end * * Modification of http://wordpress.stackexchange.com/a/41100/26350 by @kaiser */ add_filter( ‘posts_search’, function( $search, $q … Read more

Exclude file from theme editor

In general I wouldn’t recommend editing files that way and just disable it with the well known DISALLOW_FILE_EDIT or DISALLOW_FILE_MODS constants, that are checked within the map_meta_cap() function. But anyway it’s interesting to see if we can find a way to exclude files from the theme editor. Here are some ideas: There doesn’t seem to … Read more

Exclude posts with specific meta_value while sorting by a separate meta_value

You code may be $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘posts_per_page’ => ’50’, ‘meta_key’ => ‘release_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘undetermined_date_toggle’, ‘value’ => ‘true’, ) ), ‘paged’ => $paged ); $the_query = new WP_Query( $args ); this code show only those posts which … Read more

Alter secondary loop to exclude posts from current page category

This one is even more simple. Refer to the WP_Query() category parameters. I think you will want to use ‘category__not_in’. foreach ( $random_posts_cat_array as $random_post_cat ) { if ( $post_cat_slug == $random_post_cat ) { // No posts from this category! $random_posts_query_args[‘category__not_in’] = $post_cat_id; } } Edit So for example if a post is currently on … Read more

Get attached media only

All media (somewhat incorrectly) in the $wpdb->posts table will be “attachments” whether actually attached or not. “Attachments” that are actually attached will have a post_parent other than 0, so what you need are all of the attachments that have a 0 in the post_parent column, if I understand you. $args = array( ‘post_type’ => ‘attachment’, … Read more

Exclude a category from the filed under list only on some templates

You can add conditional statements before applying the logic to modify the categories. For example, I added a check that will bail and return the unmodified list of categories if we’re not on the category archive page: // Add the filter to ‘the_category’ tag. add_filter( ‘the_category’, ‘the_category_filter’, 10, 2 ); function the_category_filter( $thelist, $separator=” ” … Read more

Add exception for specific tag

The get_the_tags() function returns an array of objects. So, you can step through the this array, and unset the object for the “Featured” tag, perhaps like so: <?php $tags = get_the_tags(); foreach ( $tags as $tag_key => $tag_object ) { if ( ‘featured’ == $tag_object->slug ) { unset( $tags[$tag_key] ); } } // Continue with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)