I created a search form for my custom post types and I want to be able to place it anywhere on my site, so I created a shortcode. The vanilla form works fine, but in a shortcode, it's displaying duplicate fields. Can anyone see why it would do this? The top 3 fields are duplicates of the fields in the lower form. You can see the result at http://autismva.teebark.com/resource-finder-3.
You can see the vanilla form at http://autismva.teebark.com/resource-finder2
function resource_search_form( $form ) {
$form = '<form id="category-select" class="category-select" method="post" action="' . esc_url(admin_url('admin-post.php')) . '" >' .
wp_dropdown_categories( 'show_count=1&hierarchical=1&depth=2&show_option_none=Select by category&name=$cat_id&taxonomy=resource_cat' ) . '<br>' .
wp_dropdown_categories( 'show_count=0&hierarchical=1&depth=1&show_option_none=Select by age&name=$age_id&taxonomy=resource_age' ) . '<br>' .
wp_dropdown_categories( 'show_count=0&exclude=128&show_option_none=Select by region&name=$region_id&taxonomy=resource_region' ) . '<br>' .
'<input type="text" name="s" placeholder="Search by keyword" /><br>
<input type="text" name="tag_name" placeholder="Search by tag" />
<input type="hidden" name="action" value="resource_search_cat2" />
<button type="submit" > Search </button>
</form>';
return $form;
}
add_shortcode('resource_search', 'resource_search_form');
**The vanilla form:**
<form id="category-select" class="category-select" method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" >
<?php wp_dropdown_categories( 'show_count=1&hierarchical=1&depth=2&show_option_none=Select by category&name=$cat_id&taxonomy=resource_cat' ); ?><br>
<?php wp_dropdown_categories( 'show_count=0&hierarchical=1&depth=1&show_option_none=Select by age&name=$age_id&taxonomy=resource_age' ); ?><br>
<?php wp_dropdown_categories( 'show_count=0&exclude=128&show_option_none=Select by region&name=$region_id&taxonomy=resource_region' ); ?><br>
<input type="text" name="s" placeholder="Search by keyword" /><br>
<input type="text" name="tag_name" placeholder="Search by tag" />
<input type="hidden" name="action" value="resource_search_cat2" />
<button type="submit" > Search </button>
</form>
I hope this will work for you.
// write this action in your "after_setup_theme" hook
add_action( ' woocommerce_single_product_summary ' , ' your_function_name ' , 10 );
//define your function that contains the removal action hook.
function your_function_name()
{
remove_action( ' woocommerce_single_product_summary ' , ' woocommerce_template_single_add_to_cart ' , 30 );
}
Related
I have code like this using WordPress:
function an_max_form($id,$maxList)
{
global $wpdb;
$table_name = $wpdb->prefix . "maxform_r";
$maxrow = $wpdb->get_row( $wpdb->prepare( "SELECT id,maxlist FROM %s", $table_name ) );
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<input type="hidden" name="id" value="' . (isset( $_POST['id'] ) ? $id : $maxrow->id ) . '" />
<div>
<label for="maxList">Maximum List</label>
</div>
<div>
<input type="text" name="maxList" value="' . (isset( $_POST['maxList'] ) ? $maxList : $maxrow->maxlist ) . '"/>
</div>
<div>
<input type="submit" name="submit" value="Save" />
</div>
</form>
';
}
This form will fetch 1 row from the database and populate it into this form. But why my form doesn't return any value. I tried to debug it using echo $maxrow->id but still empty. Anyone know what is wrong with my coding?
I have a custom post type called 'bookings' that saves several fields of meta data to wp_postmeta.
I have a page that displays all the entries from this custom post type, i.e. all the bookings.
Here is the code to display my bookings:
<?php
$current_user = wp_get_current_user();
$args = array(
'post_type' => 'bookings',
'meta_query' => array(
array(
'key' => 'wedding_user',
'value' => $current_user->display_name,
'compare' => '=',
)
)
);
// Welcome
echo '<div class="user_avatar">'.get_avatar( $current_user->ID, 32 ).'</div>';
echo '<div class="user_welcome"><p>Hello '.$current_user->display_name.' <span class="user_id">(ID# '.$current_user->ID.')</span></p>';
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
if (get_post_meta( $the_query->post->ID, 'wedding_hidden_is_completed', true )==1) {
$is_complete = 'Form Complete <br /><span class="small">('.get_post_meta( $the_query->post->ID, 'wedding_hidden_date_completed', true ).')</span>';
} else {
$is_complete = 'Not Complete';
}
echo '<p class="booking_id">Booking ID: DISTR' . $the_query->post->ID . '</p>';
echo '<ul class="show_bookings">';
echo '<li>' . get_post_meta( $the_query->post->ID, 'wedding_name', true ) . '</li>';
echo '<li>' . get_post_meta( $the_query->post->ID, 'wedding_date', true ) . '</li>';
echo '<li>' . get_post_meta( $the_query->post->ID, 'wedding_package', true ) . '</li>';
echo '<li>£' . get_post_meta( $the_query->post->ID, 'wedding_price', true ). '</li>';
echo '<li>' . get_post_meta( $the_query->post->ID, 'wedding_payment_due_date', true ) . '</li>';
echo '<li>' . $is_complete . '</li>';
echo '<li>Is Viewed?</li>';
echo '<li>Actions';
echo '<ul class="actions-sub-menu">';
echo '<li>Fill out booking form</li>';
echo '<li>Pay deposit</li>';
echo '<li>Pay remaining balance</li>';
echo '<li>Email a copy of your receipt</li>';
echo '<li>View booking form</li>';
echo '</ul>';
echo '</li> <!--end actions-sub-menu-->';
echo '</ul>';
?>
<div class="pay_deposit">
<?php
require DISTRACTIONS_LOGIN_PLUGIN_DIR . 'includes/payments/deposit.php';
?>
</div> <!-- end pay deposit -->
<?php
}
} else {
echo '<p>No bookings found</p>';
}
/* Restore original Post Data */
wp_reset_postdata();
?>
under each booking is a paypal payment button - it uses paypal IPN, so nothing too complex (you will see the required file in the "pay_deposit" div).
Here is my paypal payment form:
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin'; //
$paypal_id='malik#thedistractionsband.co.uk'; // Business email ID
$booking_form_id = $the_query->post->ID;
$total_amount = get_post_meta( $the_query->post->ID, 'wedding_price', true );
$deposit_amount = $total_amount*0.2;
?>
<h3>Pay Deposit</h3>
<p>Your deposit aount of £<?php echo $deposit_amount; ?> ...</p>
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo get_post_meta( $the_query->post->ID, 'wedding_name', true ); ?> - 20% Deposit">
<input type="hidden" name="item_number" value="DISTR<?php echo $booking_form_id; ?>">
<input type="hidden" name="credits" value="510">
<input type="hidden" name="userid" value="<?php echo $current_user->ID; ?>">
<input type="hidden" name="amount" value="<?php echo $deposit_amount; ?>">
<input type="hidden" name="cpp_header_image" value="http://www.thedistractionsband.co.uk/files/2015/08/LOGO-1.1-1024x304.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="handling" value="0">
<input type="hidden" name="cancel_return" value="<?php echo get_site_url()."/payment-cancel/"; ?>">
<input type="hidden" name="return" value="<?php echo get_site_url()."/my-bookings/"; ?>">
<input name="notify_url" value="<?php echo DISTRACTIONS_LOGIN_PLUGIN_URL ?>includes/payments/paypal-ipn.php" type="hidden">
<input type="submit" border="0" name="submit" value="Pay Now" alt="PayPal - The safer, easier way to pay online!">
<div class="cards"><i class="fa fa-cc-amex"></i> <i class="fa fa-cc-mastercard"></i> <i class="fa fa-cc-visa"></i> <i class="fa fa-credit-card"></i> <i class="fa fa-cc-paypal"></i></div>
</form>
When a payment is made, it uses the following file to communicated with paypal and update my database - paypal-ipn.php
<?php
// Make wordpress functions available - so we can write to the db etc
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );
global $wpdb;
update_post_meta($booking_id, 'deposit_paid', 1);
?>
My issue is in this file. The update_post_meta function is used to add a '1' to the deposit_paid column in my wp_postmeta db table. The issue I have is, how do I define the $booking_id - making sure that it is for the booking that has been paid for.
For example, on my page that lists all my bookings, if the first has post_id 10 and I pay for that, how do I make sure that the 'deposit_paid' entry for post_id 10 is updated?
Figured it out, I need to use:
$booking_id = $_POST['item_number'];
To get the item number sent to paypal (which is the same as the post id)
I just upgraded my site to a new version WordPress 3.9.2. I noticed that one of my page is not working the way it usually does. This page is password protected and I made changes on how it looks. When I upgraded, it doesn't work anymore. In the password protected page, I have this code:
<?php
echo "<script type='text/javascript'>\nwindow.location = 'http://www.google.com'</script>";
?>
The purpose of that one is to redirect to another page. And they go hand in hand with this code below.
Here is my old code:
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>
Before the upgrade, after inputting the password it redirects me to another page, which is how I wanted it to work. But take note of the action attribute of form. In the WP 3.9.2, wp-pass.php does not exist anymore so I was looking for another code. I saw this line:
action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '"
But after inputting the password, it redirects me to the wp-login which is not what I wanted. I need help with this, which works the same way with the old code I'm using. I am not going to downgrade my WP or install any plugin. I just want the value of the action="" changed. Thanks!
I already found the answer. Maybe my files weren't compatible that's why it didn't work but here is the full code.
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>
NOTE : I am using WordPress 3.9.2
I had the same problem and i found a solution
1) Set your page private with a password
2) Insert this form in an other page (typique postpass wordpress form) :
<form action="https://exemple.com/wp-login.php?action=postpass" class="post-password-form" method="post" id="go-pro-espace">
<input name="post_password" id="exemple" type="password" size="20" /><br />
<input type="submit" value="submit">
</form>
3) Change your /wp-login.php file (root directory, at this time, this is located line 460) :
from:
wp_safe_redirect( wp_get_referer() );
to:
wp_safe_redirect( "https://exemple.fr/your-protected-page" );
Take a look to the answer: Wordpress protected page, POST form on a other page
I am building a site for some therapists using wordpress and am using the comment section of a post for a question and answer with the therapists. However I cannot find where the text is coming from on the "post comment" button. I would like to change it to "Post a Question".
The comments.php in the theme has nothing about it and I cannot find it anywhere in the main wp-comments-post.php
Any help would be great!
Thanks
The web address is http://s416809079.onlinehome.us/ask-the-therapist/
Edit: My confusion has been that I cannot find the 'post comment' anywhere. Also if I just add it then there becomes two buttons and the new one does not actually submit. Here is the code.
<?php
/**
* Comments Template
*
* #file comments.php
* #package Pilot Fish
* #filesource wp-content/themes/pilot-fish/comments.php
* #since Pilot Fish 0.1
*/
if ( post_password_required() ) : ?>
<p class="nocomments"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'pilotfish' ); ?></p>
<?php /* Stop the rest of comments.php from being processed */
return;
endif; ?>
<?php if (have_comments()) : ?>
<h6 id="comments"><?php comments_number(__('No Response to', 'pilotfish'), __('One Response to', 'pilotfish'), __('% Responses to', 'pilotfish')); ?> <i><?php the_title(); ?></i></h6>
<ol class="commentlist">
<?php wp_list_comments('avatar_size=60'); ?>
</ol>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
<nav class="pager">
<div class="previous"><?php previous_comments_link(__( '‹ previous','pilotfish' )); ?></div><!-- end of .previous -->
<div class="next"><?php next_comments_link(__( 'next ›','pilotfish', 0 )); ?></div><!-- end of .next -->
</nav><!-- end of.pager -->
<?php endif; ?>
<?php else : ?>
<?php if (comments_open()) : ?>
<?php
$fields = array(
'author' => '<p id="comment-form-author">' . '<label for="author">' . __('Name','pilotfish') . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" placeholder="'. __('name (required)', 'pilotfish').'" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30" /></p>',
'email' => '<p id="comment-form-email"><label for="email">' . __('E-mail','pilotfish') . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="email" name="email" placeholder="'. __('email (required)', 'pilotfish').'" type="text" value="' . esc_attr($commenter['comment_author_email']) . '" size="30" /></p>',
'url' => '<p id="comment-form-url"><label for="url">' . __('Website','pilotfish') . '</label>' .
'<input id="url" name="url" placeholder="'. __('website', 'pilotfish').'" type="text" value="' . esc_attr($commenter['comment_author_url']) . '" size="30" /></p>',
);
$defaults = array('fields' => apply_filters('comment_form_default_fields', $fields));
comment_form($defaults);
?>
<?php endif; ?>
The Comment Form Codex has everything you need to know about customizing the values of a Comment form.
$defaults = array(
'fields' => apply_filters('comment_form_default_fields', $fields),
'label_submit' => __('Post a Question')
);
comment_form($defaults);
That should do what you need.
set the value of the input to <input value="Post a question">
just search for the text post comment and change the value of the button tag for it,
<input name="submit" type="submit" id="submit" value="Post a Question">
Change the value attribute for the following input element:
<input type="submit" value="Post a Question" id="submit" name="submit">
If you do a search all files for "Post Comment" you should find what you are looking for.
Avoid editing your theme's files directly as your changes can be overwritten when you update your theme.
function change_comment_form_submit_label($arg) {
$arg['label_submit'] = 'Post a Question';
return $arg;
}
add_filter('comment_form_defaults', 'change_comment_form_submit_label', 11);
I have added a priority of 11 as the default is 10 and your theme may be changing it with the default priority.
The Comment Form Codex has everything you need to know about customising the values of a Comment form.
Under the class form-submit change the value.
Previous
...
<p class="form-submit">
<input id="submit" type="submit" value="Post Comment" name="submit">
...
Change to
...
<p class="form-submit">
<input id="submit" type="submit" value="Post A Question" name="submit">
...
I am having the hardest time figuring out something that I think should be simple. I need to update multiple rows in my database with one submit button. I have it working with a submit for each row now, but I need to combine it. Here's what I'm trying. Where have I gone wrong? (I've been going off of multiple tutorials I found online and I think I have things all mixed up).
Here's the form:
<?php foreach ($teams as $team):
$id[]=$team['id'];?>
<form action="?update" method="post">
<div class="team-box">
<h2><?php echo $team['name'] ?></h2>
<label for="name">Name:</label>
<input type="text" name="name" value="<?php echo $team['name'] ?>" />
<label for="name">Match Wins:</label>
<input type="text" name="mwins" value="<?php echo $team['mwins'] ?>" />
<label for="name">Match Losses:</label>
<input type="text" name="mlosses" value="<?php echo $team['mlosses'] ?>" />
<label for="name">Match Ties:</label>
<input type="text" name="mties" value="<?php echo $team['mties'] ?>" />
<label for="name">Game Wins:</label>
<input type="text" name="gwins" value="<?php echo $team['gwins'] ?>" />
<label for="name">Game Losses:</label>
<input type="text" name="glosses" value="<?php echo $team['glosses'] ?>" />
<input type="hidden" name="id" value="<?php echo $team['id'] ?>" />
</div>
Here's the PHP to handle the UPDATE:
try
{
foreach($_POST['id'] as $id) {
$sql = 'UPDATE teams SET
name = "' . $_POST['name'.$id] . '",
mwins = "' . $_POST['mwins'.$id] . '",
mlosses = "' . $_POST['mlosses'.$id] . '",
mties = "' . $_POST['mties'.$id] . '",
gwins = "' . $_POST['gwins'.$id] . '",
glosses = "' . $_POST['glosses'.$id] . '"
WHERE id = "' . $_POST['id'.$id] . '"';
$pdo->exec($sql);
}
}
catch (PDOException $e)
{
$error = 'Error adding submitted team: ' . $e->getMessage();
include 'error.html.php';
exit();
}
header('Location: .');
exit();
Thanks in advance!
There are a couple of things that need fixing.
The FORM must be outside the foreach.
The '...name="name" value="...', to agree with the _POST code, should read instead:
... name="name" value="...
This way, a single POST will submit, say,
name123="Rangers"
mwins174="123"
Then you need all IDs. You can do that by issuing, in the foreach, this:
<input type="hidden" name="id[]" value="<?php print $team['id']; ?>" />
This will result in HTML:
<input type="hidden" name="id[]" value="123" />
...
<input type="hidden" name="id[]" value="456" />
and in $_POST['id'] being an array containing 123, 456 and so on.
You could also put in HTML:
<input type="text" name="name[<?php print $team['id']; ?>]" value="...
so that $_POST['name'] would be a vector with the same keys as the values of id, and therefore:
foreach($id as $team_id)
{
// Pseudocode
UPDATE... SET name=$name[$team_id]... WHERE id = $team_id;
}
This way you have one SUBMIT, and multiple UPDATEs.
Since all your field names change for each UPDATE query, you will need to execute separate queries as you already do. I don't think you would be able to perform a single UPDATE query.
I don't understand, what's wrong with executing several update queries?