13 votes

WordPress AJAX File Upload - FrontEnd

Hi You have Use this COde For WordPress front-end AJAX file upload tutorial Code Here is my code: In my template file example.php <form enctype="multipart/form-data"> <input type="text" ...
Adnan Limdiwala's user avatar
13 votes
Accepted

admin-ajax.php doesn't work when using POST data and Axios

The issue here, I think, is how axios works. Not WordPress. But you're absolutely correct to want to use a POST request here. By default I believe axios sends data in a POST request as JSON in the ...
Jacob Peattie's user avatar
12 votes

What is the real intention for admin-post.php?

admin-post.php is like a poor mans controller for handling requests. It's useful in the sense that you don't need to process your request on an alternative hook such as init and check to see whether ...
Adam's user avatar
  • 16.4k
10 votes
Accepted

Hide the term description on the term edit page, for a given taxonomy

You could target the edit form for the post_tag taxonomy, through the post_tag_edit_form hook: /** * Hide the term description in the post_tag edit form */ add_action( "post_tag_edit_form", ...
birgire's user avatar
  • 67.1k
10 votes
Accepted

Get post ID from wp_insert_post()

You'll have to do this in two steps. First, you will create a post in the draft mode, using wp_insert_post(). The wp_insert_post itself will return to you the ID of the inserted post: <?php $...
André Gumieri's user avatar
9 votes

How do we remove the H3 tag for the reply-title I.D

Today there is a native option to do this without hacking the core, or doing tricky filters with output buffer. You just need to use the filter 'comment_form_defaults' and edit the values from '...
Felipe Araujo's user avatar
9 votes

contactform7 remove tags with "wpcf7_autop false" from functions.php

If you have already upgraded CF7 to version 5.0 or higher, then you can use the new hook: add_filter( 'wpcf7_autop_or_not', '__return_false' );
Gleb Kemarsky's user avatar
8 votes

how to set from address according to the form input email address for wp_mail()?

For this filtering the email address: add_filter( 'wp_mail_from_name', 'my_mail_from_name' ); function my_mail_from_name( $name ) { return "My Name"; } Now add a filter for the name of the email ...
Yogesh Shakya's user avatar
8 votes

Hide the term description on the term edit page, for a given taxonomy

The cleanest way to do that, removing the description field from the edit screen also in the add screen: function hide_description_row() { echo "<style> .term-description-wrap { display:...
Michel Moraes's user avatar
8 votes
Accepted

Contact Form 7 Custom Post Action

As per the CF7 Documentation, you can disable AJAX form submission by placing the following code in your wp-config.php define('WPCF7_LOAD_JS', false);
Junaid's user avatar
  • 479
8 votes
Accepted

How to call WordPress functions from a form processing script

You should never post anything to plugins files directly. It's almost always a security flaw and it prevents site owner from hardening the site properly (in perfect situation no requests to PHP files ...
Krzysiek Dróżdż's user avatar
7 votes
Accepted

How to exclude pages from the search results

Note that when we use: $query->set( 'post_type', 'post' ); then we're overriding all searchable post types, not only the page post type. That may be just fine in some cases, and we're done ...
birgire's user avatar
  • 67.1k
7 votes
Accepted

Why is there a class="screen-reader-text" on my search button?

This class is used to visually hide elements from sighted users but still allows assistive technologies like screen readers to still present those elements to users who are visually impaired. For ...
Cedon's user avatar
  • 1,659
7 votes

How to get current url in contact form 7

See this example on how to create and parse the shortcode in the contact form 7 to use it add [current_url] add_action( 'wpcf7_init', 'wpcf7_add_form_tag_current_url' ); function ...
Shibi's user avatar
  • 1,813
7 votes

How to get current url in contact form 7

according to Contact Form 7 documentation you need this: [_url] — This tag is replaced by the URL of the page in which the contact form is placed. reference: https://contactform7.com/special-mail-tags/...
Geza Gog's user avatar
  • 151
7 votes

How to disable autocomplete for inputs in contact form 7?

According to the question and answer from the developer placed here: https://wordpress.org/support/topic/autocomplete-off-3/ You just need to add the autocomplete:off option to the shortcode: [email ...
Aravona's user avatar
  • 585
6 votes

Get post ID from wp_insert_post()

Check the documentation: Return: (int|WP_Error) The post ID on success. The value 0 or WP_Error on failure. Thus: $result = wp_insert_post( $data ); if ( $result && ! is_wp_error( $...
TheDeadMedic's user avatar
  • 36.4k
6 votes
Accepted

How to handle a custom form in wordpress to submit to another page?

<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post"> <input type="hidden" name="action" value="your_action_name"> Add these in your form. Where admin-...
user119247's user avatar
5 votes
Accepted

Gravity Forms skip form if already filled out using cookie?

Here's some code on how you could simply leverage the gform_after_submission hook of Gravity Forms to set a cookie based on your form ID once submitted, then check for that on the confirmation page by ...
brianjohnhanna's user avatar
5 votes
Accepted

Genesis - Customize search form

I'm not sure why you're getting a 500 error. Likely because you're trying to use a function before it's been defined. But I think you're going about the problem the wrong way. Genesis does provide a ...
Nathan Johnson's user avatar
5 votes
Accepted

How to disable autocomplete for inputs in contact form 7?

Autocomplete tag in form settings does not work anymore (as today Contact Form 7 plugin version 5.1.3. The only solution which worked for me was to add custom attributes thanks to https://...
Arnis Juraga's user avatar
5 votes
Accepted

How to save contact form 7 data in Custom Post Types (CPT)

If you want to save the Mail Content after the Contact Form was sent (or failed), you can use the wpcf7_mail_sent and wpcf7_mail_failed Hookes like this: add_action('wpcf7_mail_sent','...
HU is Sebastian's user avatar
5 votes

Use a PHP file as action for a form in a WordPress plugin, what's the correct way?

To be honest, you should never use a PHP file as action attribute for a form in WordPress. WordPress already has API for this and you should use this instead. Why? Because it's always better if your ...
Krzysiek Dróżdż's user avatar
5 votes
Accepted

Password protected page with a form submits for me fine but for others redirects them back to the password prompt

When a user logs into a protected page, WordPress sets a cookie. We can check for the existence of that cookie with this conditional: if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) { // Do ...
Valerii Vasyliev's user avatar
4 votes

Add error message on password protected page

Following up from fuxia's answer. The complete snippet, including the check if the page load came from the same page, would be: add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg' );...
Stan Derksen's user avatar
4 votes

Why when I submit a form in wordpress it loads a 404 page though URL is correct

Try to change name="email" to something like name="my_theme_email", do the same with all your field it sounds like some name are reserved with WordPress when sending form data. I got the the same ...
Thierry Edou's user avatar
4 votes

Success message in comment form

Without Ajax or plugins. Add to function.php: add_action( 'set_comment_cookies', function( $comment, $user ) { setcookie( 'ta_comment_wait_approval', '1' ); }, 10, 2 ); add_action( 'init', ...
wp-mario.ru's user avatar
4 votes

wp_dropdown_categories with multiple select

wp_dropdown_categories has a filter applied to the output that is called right before the function returns or echos the output. With this you can add a filter to your funtions.php file that ...
Tunji's user avatar
  • 2,921
4 votes

$_POST form request with admin-post

The short answer is that you have to do all the work: save the user input in the database, check for errors or success, and redirect wherever you want when finished. If you want to redirect to the ...
juananruiz's user avatar
4 votes

Hide the term description on the term edit page, for a given taxonomy

If you also need to hide the description field in the add form use this code /** * Hide the term description in the edit form */ add_action( '{taxonomy_slug}_add_form', function( $taxonomy ) { ?...
iwanuschka's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible