admin管理员组

文章数量:1392007

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 ?

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 ?

Share Improve this question edited Feb 7, 2020 at 17:09 wplearner asked Feb 6, 2020 at 23:11 wplearnerwplearner 4892 gold badges9 silver badges27 bronze badges 11
  • 1 For retrieving terms, we use functions like get_terms() and not get_post_meta().. – Sally CJ Commented Feb 6, 2020 at 23:16
  • @SallyCJ okay I will try this. – wplearner Commented 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 Commented 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 Commented 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 Commented Feb 7, 2020 at 17:15
 |  Show 6 more comments

1 Answer 1

Reset to default 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.

本文标签: custom post typesgetpostmeta returns empty array for terms