I am currently trying to exclude specific products from the WooCommerce recent products widget. Specifically, I want to prevent products with the custom meta field _age_limit
set to “大人向け(ie,Adult)” from being displayed.
I added the following code to my functions.php
, but it’s not working as expected:
add_filter('woocommerce_shortcode_products_query', 'exclude_adult_products_from_recent_products', 10, 3);
function exclude_adult_products_from_recent_products($query_args, $atts, $loop_name){
if( $loop_name == 'recent_products' ){
$query_args['meta_query'][] = array(
'key' => '_age_limit',
'value' => '大人向け',
'compare' => '!=',
);
}
return $query_args;
}
_age_limit
field is a custom meta field for the products.I have confirmed that the tags are correctly stored in the database, and when I tested the SQL query directly in phpMyAdmin, it returned the expected results. Here is the SQL query I used:
SELECT * FROM ierd_postmeta WHERE meta_key = ‘_age_limit’ AND meta_value = ‘大人向け’;
The query successfully returns the expected products with the tag “大人向け.” However, the WooCommerce filter code doesn’t seem to exclude these products from the recent products widget.
Below is how I added the custom meta field for age limit in functions.php
::
function custom_product_general_fields() {
woocommerce_wp_select( array(
'id' => '_age_limit',
'label' => __( 'Age Limit', 'woocommerce' ),
'options' => array(
'全年齢' => __( '全年齢', 'woocommerce' ),
'大人向け' => __( '大人向け', 'woocommerce' ),
),
));
}
add_action( 'woocommerce_product_options_general_product_data', 'custom_product_general_fields' );
I am really struggling with this issue, and I’m not sure why this filter isn’t working as expected. Could someone please help me?
Any advice on how to debug or resolve this problem would be greatly appreciated.
Thank you so much for your assistance!
]]>I’m using the “Extended Filters & Sorting — Filter by Meta Queries” feature to pull only posts in my custom post type with an ‘end_date’ in the future. If I manually hardcode a date as the FIELD VALUE (e.g., 2023-12-26), it works perfectly and pulls out the 2 posts I currently have matching that. However, if I try to use “today” or “now” (I’ve tried various versions with/without quotes, with/without parenthesis, etc.), I get “No results found”. Any thoughts? Thanks!
]]>Projects
and it has multiple authors for each post. I’m using “Co-Authors Plus” to achieve multiple authors. I want to filter the post type listing so that current logged-in user sees only records that contain their account as an author of the post.
I am trying to use this query, but it returns nothing:
add_action('pre_get_posts', 'filter_posts_list');
function filter_posts_list($query)
{
//$pagenow holds the name of the current page being viewed
global $pagenow, $typenow;
//$current_user uses the global
global $current_user;
//Shouldn't happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php
if(!current_user_can('administrator') && current_user_can('edit_posts') && ('edit.php' == $pagenow) && $typenow == 'projects') {
//global $query's set() method for setting the author as the current user's id
$current_user_id = $current_user->ID;
$query->set( 'tax_query', array(
array(
'taxonomy' => 'author',
'field' => 'term_id',
'terms' => $current_user_id,
),
));
}
}
How can I make this query filter by authors with the exact user ID as the current user in the post?
]]>I would like to show a list of upcoming events as in the below link under “Our Programs” section with the immediate upcoming one highlighted on the left side and the list on the right side with the option of vertical scrolling.
Someone please guide me on how to accomplish this, using free version of Events Manager. In case if it is not feasible with this, are there any alternatives available to accomplish this without having to go for paid plugins or extensions.. Any help would be highly appreciated.
]]>I use the Kodex Posts likes plugin. The plugin uses the meta_key kodex_post_likes_count
The query I try is something like
'meta_key' => 'kodex_post_likes_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
But in the block settings of AQL I get the following message.
Post Meta Query
This post type has no registered post meta to query
I defenetly have votings stored under the post meta meta_value_num
Hope you can help me with this
]]>The website is built using Elementor and Crocoblock plugins.
//Alter query to exclude posts that are outdated, or whose category is hidden
function mts_alter_query($query){
if(($query->get("post_type") === "product" && !is_admin() && !$query->is_singular()) || ($query->is_search() && !is_admin())){
//$query->set("s", "chelsea");
//Hide outdated posts
$query->set("meta_key", "match-date");
$query->set("meta_value", date("Y-m-d"));
$query->set("meta_compare", ">");
//Hide posts that belong to a hidden category
$hidden_cat_ids = get_hidden_category_ids();
$original_tax_query = $query->get( 'tax_query', [] );
$new_tax_query = array(
array(
"taxonomy" => "product_cat",
"field" => "term_id",
"terms" => $hidden_cat_ids,
"operator" => "NOT IN"
),
$original_tax_query
);
$query->set("tax_query", $new_tax_query);
}
}
]]>$args = array(
‘s’ => $title,
‘post_type’ => ‘ad_post’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => 100, //New Custom Code
‘post__in’ => (!empty($postArr))? $postArr : [],
‘tax_query’ => array(
$category,
$ad_types,
),
‘meta_query’ => [
‘relation’ => ‘AND’,
$price,
$custom_search,
[
‘relation’ => ‘OR’,
$priceType,
],
],
‘order’ => $order,
‘orderby’ => $orderBy,
‘paged’ => $paged,
);
$price = array(
‘key’ => ‘price’,
‘value’ => array($_GET[‘min_price’], $_GET[‘max_price’]),
‘type’ => ‘numeric’,
‘compare’ => ‘BETWEEN’,
);
$priceType = array(
‘key’ => ‘price_type’,
‘value’ => array(‘Negotiable’,’Fixed’,’on_call’),
‘compare’ => ‘IN’
);
I have also tax_query so all combination not working together.
So I need to display on call post with price range filter. Always price filter remove price type filter.
Which post have on call then in postmeta table has price = blank and price_type = on_call
and which ad have price type = Fixed and price = 100 or some other value.
Please help.
]]>hierarchical
set to true. On those pages we want to display the child items, but separately also show the sibling items. For this we are trying to use the Custom Post Type block in both instances.
It doesn’t appear to be possible at the moment. We did notice that if we were using “Pages” as the CPT that additional attribute settings appear allowing “Display child pages of current page” and “Enter page ID to display its child pages”, but that is fixed to Pages only rather than all CPTs that are hierarchical. So that would be our first request, to allow this for all hierarchical CPTs.
Secondly was wondering if it would be possible to add more filters into the core functionality, specifically was thinking of the function getwid_build_custom_post_type_query() and being able to filter the query_args bases on the attributes passed. This, along with the above hierarchical attributes, would allow much more dynamic frontend changes.
]]>Is it correct to use ‘posts_per_page’ => 10 ?
$name = $post->post_name; //get the slug of the current CPT actors
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'meta_query' => array(array(
'key' => 'actors',
'value' => $post->ID,
'compare' => 'IN',
),
),
);
$loop = new WP_Query($args)
]]>Now I want that when I access the page of the CPT-actors I get a list of all the posts that actor has.
$name = $post->post_name; //get the slug of the current CPTactors
$args = array(
'post_type' => 'post',
'posts_per_page' => 199,
'meta_query' => array(array(
'key' => 'actors',
'value' => $name,
'compare' => 'LIKE',
),
),
);
$loop = new WP_Query($args)
.
.
.
I’m trying this but nothing comes out. any ideas?
]]>