1

I have custom post type of jobs and in this post type I have two custom taxonomies. For job post I selected few terms from both these taxonomies in admin panel but when I tried to access these on front end using get_post_metait is displaying these terms as empty. I have two taxonomies (city, industry). I am getting city terms like this

[_job_city] => Array
    (
        [0] => 
    )

I am getting industry terms like this

[_company_industry] => Array
    (
        [0] => s:1:"1";
    )

Any suggestion ?

11
  • 1
    For retrieving terms, we use functions like get_terms() and not get_post_meta()..
    – Sally CJ
    Feb 6, 2020 at 23:16
  • @SallyCJ okay I will try this.
    – wplearner
    Feb 6, 2020 at 23:18
  • You can use the search form on the WP developer resources site, to find the function that best suites your needs.
    – Sally CJ
    Feb 6, 2020 at 23:29
  • 1
    Actually I fixed this invalid taxonomy error by using init hook. Previously I was trying to access this without any function.
    – wplearner
    Feb 7, 2020 at 17:08
  • 1
    @SallyCJ yes you are right as I was trying to access these terms before registering these so that is why I had invalid taxonomy error. Instead of get_post_meta now I am using wp_get_post_terms which is working for me. You can add your answer and I will accept your answer if you want. Thank you so much for your time once again.
    – wplearner
    Feb 7, 2020 at 17:15

1 Answer 1

1

Instead of get_post_meta now I am using wp_get_post_terms function to access job post terms and it is working for me. It is working correctly for both these taxonomies.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.