admin管理员组

文章数量:1278881

I try to to make compare by company title so I need to send this title as variable to meta query value. I use this code and get value = NULL. Please tell me why?

        $company_name = the_title( );
        $params = array(
         'meta_query' => array(
           array( 
           'key' => 'user_company',
           'value' => $company_name
          )
         )
       );

I try to to make compare by company title so I need to send this title as variable to meta query value. I use this code and get value = NULL. Please tell me why?

        $company_name = the_title( );
        $params = array(
         'meta_query' => array(
           array( 
           'key' => 'user_company',
           'value' => $company_name
          )
         )
       );
Share Improve this question asked Oct 8, 2021 at 12:39 MegosMegos 52 bronze badges 4
  • the_title does not return the title, it echo's the title, it's the wrong function – Tom J Nowell Commented Oct 8, 2021 at 13:40
  • But var_dump ($company_name) gives me the company title... – Megos Commented Oct 8, 2021 at 13:50
  • Thank you! I use get_the_title() and it works now. – Megos Commented Oct 8, 2021 at 13:52
  • the_title is the wrong function, even if it returns a value it still outputs to the browser, you must use the dedicated function that returns the title instead, get_the_title – Tom J Nowell Commented Oct 8, 2021 at 13:52
Add a comment  | 

1 Answer 1

Reset to default 0

Use get_the_title to get the title. the_title is for when you want to output directly to the browser.

本文标签: meta queryHow to send variable to wp metaquery value