0

I have simple question:

How to change this array

Array ( [0] => taxonomy-term-1 [1] => taxonomy-term-2 [2] => taxonomy-term-3 )

to this array?

array( 'taxonomy-term-1', 'taxonomy-term-2', 'taxonomy-term-3' )

Why I am asking for that:

$slugs = wp_get_post_terms($post->ID,'ml_patternsCustomTaxonomy',['fields'=>'slugs']);

returns

Array ( [0] => taxonomy-term-1 [1] => taxonomy-term-2 [2] => taxonomy-term-3 )

but

array(
    'title'       => $title,    
    'content'     => trim($patternContent),
    'categories'  => $slugs
)

doesn't work, and

//
'categories'  => array( 'taxonomy-term-1', 'taxonomy-term-2', 'taxonomy-term-3' ),

works.

Why?

3
  • 3
    They're the same. An associative array that's keyed with 0-based consecutive non-negative integers is the same as an indexed array. Commented Nov 21, 2021 at 0:37
  • I've updated my post, if u can look at this :) Commented Nov 21, 2021 at 0:58
  • do you want something like this stackoverflow.com/questions/4550976/… Commented Nov 21, 2021 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.