Creating short code for search form

Question

I added this snippet in my functions.php file but it doesn’t execute the categories from foreach. It only shows the keywords field and it works fine but it’s not showing the categories names.

function jobsform_function($atts) {  
    return '
      <form class="home-job-search" method="GET" action="https://website.com/jobs/jobs/">
        <div class="home-keywords">
          <input type="text" id="search_keywords" name="search_keywords" placeholder="Enter Keywords" />
        </div>
        <div class="home-categories">
          <select id="search_category" name="search_category">
              <?php foreach ( get_job_listing_categories() as $cat ) : ?>
                 <option value="<?php echo esc_attr( $cat->term_id ); ?>">
                    <?php echo esc_html( $cat->name ); ?>
                 </option>
              <?php endforeach; ?>
          </select>
        </div>
        <div class="home-search-button">
          <input type="submit" value="Search" />
        </div>
      </form>';
}
add_shortcode('jobsform', 'jobsform_function');

this is the result
search form
Any suggestions please?

0
Ahmed Ramy Abd Allah 2 years 2020-12-15T03:10:30-05:00 0 Answers 4 views 0

Leave an answer

Browse
Browse