First i tried to create a filter with ( pre_get_posts ) but finally i decided to create a page archive for my custom post (date);
I take the classic loop of archive page Wordpress and had $args
$args = array(
'post_type' => 'date',
'orderby' => array('meta_value_num' => 'DESC'),
'meta_key' => 'my_metakey_from_CMB2',
'meta_compare' => 'EXISTS',
);
$archive_date_query = new WP_Query($args);
My meta_key is call with the plugin CMB2 like this ( 'ID' are meta_key for $args) :
add_action('cmb2_admin_init', 'agenda_for_cpt_date');
function agenda_for_cpt_date()
{
$prefix = '_cp_agenda_';
$cmb_cpd = new_cmb2_box(array(
'id' => $prefix . 'properties',
'title' => esc_html__('Propriétés de l\'agenda', 'cmb2'),
'object_types' => array('date'),
'context' => 'after_title',
'priority' => 'high',
));
// Groupes pour les dates si plusieurs dates //
$group_field_id = $cmb_cpd->add_field(array(
'id' => $prefix . 'group',
'type' => 'group',
'repeatable' => true,
'description' => esc_html__('', 'cmb2'),
'options' => array(
'group_title' => esc_html__('Agenda {#}', 'cmb2'), // {#} gets replaced by row number
'add_button' => esc_html__('Ajouter un nouvel agenda', 'cmb2'),
'remove_button' => esc_html__('Supprimer agenda', 'cmb2'),
'sortable' => true, // beta
'closed' => true, // true to have the groups closed by default
),
));
$cmb_cpd->add_group_field($group_field_id, array(
'name' => 'Date et heure de début',
'id' => $prefix . 'debut',
'type' => 'text_datetime_timestamp',
));
$cmb_cpd->add_group_field($group_field_id, array(
'name' => 'Date et heure de fin',
'id' => $prefix . 'fin',
'type' => 'text_datetime_timestamp',
));
}
if i call directly the field (debut) in my $arg like this :
$args = array(
'post_type' => 'date',
'orderby' => array('meta_value_num' => 'DESC'),
'meta_key' => '_cp_agenda_debut',
'meta_compare' => 'EXISTS',
);
$archive_date_query = new WP_Query($args);
My query give me 0 custom posts : date
But if i call the meta key : 'meta_key' => '_cp_agenda_group',
My query give me all the custom posts : date but i've no control on 'meta_key' => '_cp_agenda_debut',
This is a var dump of the key ('_cp_agenda_groupenter code here
' for '_cp_agenda_debut')
array(1) { [0]=> array(2)
{ ["_cp_agenda_debut"]=> int(1655875800)
["_cp_agenda_fin"]=> int(1654542000)
} }
If i resume... is it possible to access a meta_key that is in an array ??? with a wordpress query ?
I've search a lot... but no result.
I think my query is correct. I've test it with simple meta_key.
I always tried to make this without success :
$ga = '_cp_agenda_group';
'meta_key' => $ga[0]['_cp_agenda_debut'],