I modified the Searchform.php to:
'search_id' => 'id', 'form_action' => ( 'http://local.amleo.com/newps/pulldata.php'
For the first Search widget, to go to a custom PHP page that displays results for something else.
The next Search Widget, I'd like to search the category "AML Hot Topics". Not sure how I can do that. Any ideas??
So you can visualize: http://i.imgur.com/HSd9EEZ.png
The 1st Search is the one I modified the Searchform.php for. The 2nd is the one I'm not sure about.
I'm no super-duper PHP wizard by any means, but I can follow directions pretty decently.
You don't need two target for search, instead you can do it using something like this
One form for newps
<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
<input type="text" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" id="s" />
<input type="hidden" value="newps" name="key" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_e('Search','Aggregate'); ?>" />
</form>
Another for AML
<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
<input type="text" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" id="s" />
<input type="hidden" value="aml" name="key" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_e('Search','Aggregate'); ?>" />
</form>
Create a search.php file in your theme's root folder, something like this
get_header();
// if you get `key` then it will be your custom search
// otherwise, default search will be performed
if(!empty($_GET['key'])) {
$key = $_GET['key']; // it will be either 'newps' or 'aml'
$search = $_GET['s'];
// modify the query using your $key and $search param
query_posts(...);
}
if (have_posts()) :
while(have_posts()): the_post();
// the_title() and more...
endwhile;
endif;
// reset the query if modified
if(!empty($key)) wp_reset_query();
get_sidebar();
get_footer();
Related
I have added a search bar for my woocommerce products page. Some searches go to archive-product.php and some go to single-product.php. I want to disable the single-product shortcut. I have tried searching my problem on stackoverflow and google but all I get is search filter plugins.
How do I stop my search from going to single products and automatically search on my inventory list page?
To simplify my problem here is how it looks:
When haven't search anything:
When I search "wheel" :
When I search "air filter":
This is my search bar code:
<div class="search-wrap">
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="search">
<label class="screen-reader-text " for="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>"><?php esc_html_e( 'Search for:', 'woocommerce' ); ?></label>
<input type="search" id="woocommerce-product-search-field-<?php echo isset( $index ) ? absint( $index ) : 0; ?>" class="search-field searchTerm" placeholder="<?php echo esc_attr__( 'Search products…', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
<button type="submit" class="searchButton" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>"><i class="fa fa-search"></i>
</button>
<input type="hidden" name="post_type" value="product" />
</div>
</form>
</div>
Add the following to functions.php
add_filter( 'woocommerce_redirect_single_search_result', '__return_false' );
Tested on fresh install and works.
Fixed by adding this into my functions.php
add_filter( 'woocommerce_redirect_single_search_result', 'my_remove_search_redirect', 10 );
function my_remove_search_redirect() {
return false;
}
Answer found here:
https://removewcfeatures.com/disable-woocommerce-single-search-result-redirect/
I want to modify my Wordpress site theme feature, and modify the search tool from header to show just related products, instead showing me blog post. I searched a little, and found that just need to modify the query, so can use for searching woo products. This is my current search query:
<form role="search" method="get" class="et-search-form" action="<?php echo
esc_url( home_url( '/' ) ); ?>">
<?php
printf( '<input type="search"
class="et-search-field" placeholder="%1$s" placeholder="%2$s" name="s"
title="%3$s" />',
esc_attr__( 'Search …', 'Divi' ),
get_search_query(),
esc_attr__( 'Search for:', 'Divi' )
);
?>
<button type="submit"
id="searchsubmit_header"></button>
</form>
i found that i should put this line:
<input type="hidden" class="" value="product" name="post_type" />
bellow
<form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
So it should looks like this:
<form role="search" method="get" class="et-search-form" action="<?php echo
esc_url( home_url( '/' ) ); ?>">
<input type="hidden" class="" value="product" name="post_type" />
but still show me mixed results from Woo Products and Pages/Blog posts.
So my question is what to modify in query to search just for WooCommerce products instead of blog posts. Thanks in advance.
Welcome to Stack Overflow.
Add a hidden field to search for products.
<input type="hidden" value="product" name="post_type">
Live example from one of my sites.
Example has separate forms to search posts, products, news.
Best wishes,
Mitchell
I'm trying to create a custom index.php page and would like to make the users search result save inside of a search box. Here was what I peiced together that works a little bit:
<li class="result-searh"><form role="search" method="get" id="searchform" class="searchform" action="http://droogle.dil/">
<div>
<input type="text" value=<?php printf( esc_html__( '%s', stackstar ), '<span>' . get_search_query() . '</span>' ); ?> name="s" id="s">
<input type="submit" id="searchsubmit" value="Search">
</div>
</form></li>
Which looks like this:
When I search for "my search". As you can see, its is showing up. Just a bit funny looking. I am quite terrible at PHP so forgive me if this looks bad. I Frankenstein'd this code together using other plugins' code.
-
EDIT: changed it to this:
<input type="text" value=<?php printf( esc_html__( '%s', stackstar ), get_search_query()); ?> name="s" id="s">
and now when I search for "Hello I am joe" inspecting the element gives me this:
<input type="text" value="hello" I="" am="" joe="" name="s" id="s">
Going out on an untested limb and proposing enclosing the <php .. ?> with double quotes might fix this:
<input type="text" value="<?php printf( esc_html__( '%s', stackstar ), get_search_query()); ?>" name="s" id="s">
I am trying to define block of html $result_html=""; to use inside the shortcode like this:
[ms-protect-content id="7001"]' . $result_html . '[/ms-protect-content]
I am trying to define the following html as a $result_html:
<p>
<input type="hidden" name="product_id" value="<?php echo $post->ID; ?>" />
<input type="submit" id="send_product_enquiry" value="<?php _e( 'Send Enquiry', 'wc_enquiry_form' ); ?>" class="button" />
</p>
<?php do_action( 'product_enquiry_after_form' ); ?>
I ran into the problem with correctly writing the quotes inside the quotes.
I know that I should add a backslash \ before the quotes to escape them, but in this case it is just getting a way to confusing for my understanding of php.
My code currently looks like this with my corrections:
$result_html='
<p>
<input type="hidden" name="product_id" value="<?php echo $post->ID; ?>" />
<input type="submit" id="send_product_enquiry" value="<?php _e( \'Send Enquiry\', \'wc_enquiry_form\' ); ?>" class="button" />
</p>
<?php do_action( \'product_enquiry_after_form\' ); ?>
';
According to Dreamweaver, there are no errors, but when the code is rendered, it is not correct, the <?php echo $post->ID; ?> is not passing, but I can't find my errors.
Can someone please correct me, thanks
btw, I changed from $result_html=""; ( double quotes ) to $result_html=''; ( single quotes ), not sure if it's ok
You seem to have a fundamental lack of understanding about how quoting works in php. There is no reason for you to have php opening and closing tags inside of single quotes!
Let me know how this works.
$result_html='
<p>
<input type="hidden" name="product_id" value="' .$post->ID . '" />
<input type="submit" id="send_product_enquiry" value="' . _e( 'Send Enquiry', 'wc_enquiry_form' ) . '" class="button" />
</p>' . do_action( 'product_enquiry_after_form' );
This is my first time trying to integrate paypal into a wordpress site - so I might need a bit of hand holding. I'm building a custom plugin for a client where the admin creates booking forms for events and assigns them to users. The user can then log in and see their assigned booking forms and fill them out. Once filled out, the user can then pay the price of their booking.
Let say the user has filled out their booking form and is now ready to pay for their booking, they click on "pay" and are taken to a payment page (www.yoursite.com/deposit/?booking-id=xxx) which is essentially just a message and a pay button and hidden form fields for paypal. Here is the php for that page:
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin'; //
$paypal_id='malik#thedistractionsband.co.uk'; // Business email ID
$booking_form_id = get_query_var( 'booking-id' );
$current_user = wp_get_current_user();
?>
<?php
// The Query
$bookings_query = new WP_Query(
array(
'post_type' => 'bookings',
'p' => $booking_form_id
)
);
// The Loop
if ( $bookings_query->have_posts() ) {
while ( $bookings_query->have_posts() ) {
$bookings_query->the_post();
?>
<h2>Pay Deposit</h2>
<p>Hello <?php echo $current_user->display_name; ?> blah blah blah</p>
// Paypal form
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<?php
$total_amount = get_post_meta( $bookings_query->post->ID, 'wedding_price', true );
$deposit_amount = $total_amount*0.2;
?>
<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( $bookings_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>
<?php
}
/* Restore original Post Data */
wp_reset_postdata();
} else {
echo '<p>No bookings found</p>';
}
?>
This all works fine, and actually payments go through fine. I'm now trying to work on the paypal-ipn.php file which is where I want to create communications with paypal and add an entry to the post_meta database table when payment is successful.
So far I don't have much, but here is my paypal-ipn.php
<?php
global $wpdb;
update_post_meta(52, 'deposit_paid', 1);
?>
I'm hoping that this would update deposit_paid to '1' (for post_id 52 - which I will dynamically change to the booking that has been paid for....once I've got this working).
Currently it does nothing, Am I doing something wrong here?
You have a few options here - the easiest (as its just a php page) is to add the following:
// Make wordpress functions available - so we can write to the db etc
require_once realpath('/wp-load.php');
With the correct relative path to the wp-load.php file (its in the root of WordPress).
You need this to enable the functions and get update_post_meta(); to work etc...
When developing you should have:
define('WP_DEBUG', true);
Set up in your wp-config.php as this will alert you to problems.
Option #2 is to make a function and hook the into a WordPress hook when the user submits the form. This is more complex and I feel not what you are after.