Hi?@charlie67p
I found the root cause of the issue.
The main reason is a snippet code in your child theme that alters all custom queries on this template, here is your code:
function my_pre_get_posts( $query )
{
// do not modify queries in the admin
if(is_admin() ) {
return $query;
}
if (( $query->is_tax() ) OR (is_post_type_archive('projet')) ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'your_field_name');
$query->set('order', 'DESC');
}
if (is_front_page() ) {
$query->set('cat', '-14');
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
There is no check in this hook to determine whether the query object is the main query. This will affect all custom queries. You can test it by dropping a core dynamic block like latest-posts on this template, you will see that no items are loaded.
Since MFB version 1.1.x, I’ve added more features under the hood to support more complex fields in future versions, that’s why it fails to display the meta value.
The solution:
In my part, I’ll add some code in the next version of the plugin to cover these rare use cases, so it sill can display the value for basic fields like version 1.0.x.
For your child theme, I suggest you should add a simple check in your hook to solve all potential issues related to this query stuff, here is the code:
function my_pre_get_posts( $query )
{
// do not modify queries in the admin
if(is_admin()) {
return $query;
}
// Only modify the main query
if ( ! $query->is_main_query() ) {
return $query;
}
if (( $query->is_tax() ) OR (is_post_type_archive('projet')) ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'your_field_name');
$query->set('order', 'DESC');
}
if (is_front_page() ) {
$query->set('cat', '-14');
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
After adding the check, the latest version of the block will work fine for your fields, you can test it yourself.
Thanks, Phi.
-
This reply was modified 1 year, 8 months ago by Phi Phan.