0
votes

I'm looking to query my posts via a custom field that I've created on my page. But the custom field is an array of values. So the custom field 'country' could look like this

country => usa,africa,united kingdom,poland

What's confusing me is how to query posts with a custom field which is an array seperated with ','?

I've tried quite a few solutions on here with no success.

Any help would be greatly appreciated!

2

2 Answers

0
votes

Did you write "usa,africa,united kingdom,poland" as the value for one key?

That would be a string and not an array.

0
votes

https://codex.wordpress.org/Taxonomies

function people_init() {
    // create a new taxonomy
    register_taxonomy(
        'countries',
        'post',
        array(
            'label' => __( 'Countries' ),
            'rewrite' => array( 'slug' => 'countries' ),
            'capabilities' => array(
                'assign_terms' => 'edit_guides',
                'edit_terms' => 'publish_guides'
            )
        )
    );
}
add_action( 'init', 'countries_init' );