Creating short code for search form


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="">
        <div class="home-keywords">
          <input type="text" id="search_keywords" name="search_keywords" placeholder="Enter Keywords" />
        <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 ); ?>
              <?php endforeach; ?>
        <div class="home-search-button">
          <input type="submit" value="Search" />
add_shortcode('jobsform', 'jobsform_function');

this is the result
search form
Any suggestions please?

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

Leave an answer