Support

Account

Home Forums General Issues Search post for ACF value via form input

Helping

Search post for ACF value via form input

  • Hello,

    I’ve a custom post type “downloads” with a custom field “password”.
    The user should be able to type in the password in a front end html form and when there is a match the user should be redirected to the article….
    How could I achive this?

  • The simplest method is to create a form that has a field with a name that does not conflict with any WP reserved words

    
    <form ....>
      <input name="post_passcode"  .....>
    </form>
    

    This is just the basics, of course you should also add a nonce field as well as sanitizing the input.

    
    add_action('init', 'test_form_passcode');
    function test_form_passcode() {
      if (!isset($_POST['post_passcode'])) {
        return;
      }
      // sanitize
      // WP_Query
      // If results, loop, get post permalink
      wp_redirect($post_permalink);
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.