You can use custom field.
For example, you could name it taxonomy
, and then in your template, use get_post_meta()
to retrieve the taxonomy:
$post_id = get_the_ID(); // the ID of the current post
$taxonomy = get_post_meta( $post_id, 'taxonomy', true );
And change the 'taxonomy' => 'catmaison'
in your code to:
'taxonomy' => $taxonomy
Example:
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
),
);
UPDATE
I normally don’t suggest any plugins in my answer, but in your case, it might be easier for you to just use a plugin like ACF.
So go ahead, install and activate it, and follow the documentation on creating a custom field. But as an example, let’s use the same name as I’ve suggested before: taxonomy
. It should be a simple Text field:
(Update: For other readers, the text field looks like below.)
Now in your page template, you can use this code to retrieve the taxonomy (slug) associated with the specific page:
$taxonomy = get_field( 'taxonomy' );
And then as I’ve mentioned before, change the 'taxonomy' => 'catmaison'
in your code to:
'taxonomy' => $taxonomy