halohtlo
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Retrieving image from MySQL and enlarging it on clickI found a solution, can be closed now.
Thanks.Forum: Developing with WordPress
In reply to: Can’t understand how wp_handle_upload worksThank you very much, I will try it now.
Forum: Developing with WordPress
In reply to: Exclude tag from searchHere’s my code thanks to the people from this forum that helped me finish it.
Feel free to use it.Functions.php
add_action('wp_ajax_data_fetch' , 'data_fetch'); add_action('wp_ajax_nopriv_data_fetch','data_fetch'); function data_fetch() { $post_ids = array(2438, 379, 2729, 2571, 1830, 1832, 1819, 1824, 1826, 2415, 1828, 3155, 2752); $the_query = new WP_Query(array( 'posts_per_page' => -1, 's' => esc_attr($_POST['keyword'] ), 'post_type' => 'page', 'post__not_in' => $post_ids ) ); if( $the_query->have_posts() ) : while( $the_query->have_posts() ): $the_query->the_post();?> <div class="DisplayLiveSearchItems"> <img src="" style="width:35px;height:25px;position:relative;float:left;padding-right:1%"/><a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_title();?></a> </div> <?php endwhile; wp_reset_postdata(); endif; die(); }Javascript file ( You can name it whatever you want )
function fetch(){ jQuery.ajax({ url: "https://www.yourwebsite.com/wp-admin/admin-ajax.php", type : "POST", data: { action: 'data_fetch', keyword: jQuery('#keyword').val() }, success: function(data) { if ( jQuery('#keyword').val() == "" ) { jQuery('#datafetch').html(""); } else { jQuery('#datafetch').html( data ); } } }); };The page you want the search form to be used at:
<input type="text" class="demoInputBox" name="keyword" id="keyword" placeholder="Search" onkeyup="fetch()"/> <div id="datafetch">Your search results will appear here</div>Style.css
.demoInputBox { padding: 10px; width:40%; border: 0; border-radius: 15px; margin: 0px 5px 15px; } .DisplayLiveSearchItems { font-size:20px; width:25%; position:relative; border:3px double rgba(28,110,164,0.9); font-family:sans seriff; }- This reply was modified 7 years ago by halohtlo.
Forum: Developing with WordPress
In reply to: Can’t understand how wp_handle_upload worksI’d like to just send it as an attachment but when I try with a normal code it just won’t get sent and I have a hard time understanding how wp_handle_upload works.
Thank you very much mate.I also found something useful in the documentation and updated it a little bit.
Here’s a working code for excluding pages by their ID’s for anyone having problems with it.$post_ids = array(2461); $the_query = new WP_Query(array( 'posts_per_page' => -1, 's' => esc_attr($_POST['keyword'] ), 'post_type' => 'page', 'post__not_in' => $post_ids ) );Looks like the solution I’ve been searching for although it didn’t work out in the first place I had to add one more ‘if’ condition.
Thank you for the help mate, much appreciated.Do you have any idea how can I exclude pages from being searched with my current code?
For some reason I can’t edit the main post,
I forgot to add the form itself:<input type="text" name="keyword" id="keyword" onkeyup="fetch()"/> <div id="datafetch">Search results will appear here</div>Forum: Developing with WordPress
In reply to: Can’t get previous_links working properlySorry for double posting, HTTP referrer worked out well.
Thank you for the help and keep up the good work.
Much appreciated.Forum: Developing with WordPress
In reply to: Can’t get previous_links working properlyThank you for the feedback.
I will try it tonight and let you know if it has worked.Forum: Developing with WordPress
In reply to: Custom autocomplete search form with AjaxHey there, just a few head-ups,
1. Including a file in a wordpress page is a little bit more complicated and you must include the full path like :
include('wp-content/themes/street-business/mysearch.php')
The file itself must be placed inside your theme’s folder and you call it this way.2. As for JavaScript, it’s a good practice to put them in seperate .js files and include them like :
script type="text/javascript" src="<?=get_template_directory_uri();?>/js/avtochsrchjs.js">Hope I was helpful.
Thank you very much.
Thank you all for the help.
Sorry, I didn’t really understand your answer. I don’t have a shopping cart plugin, it’s custom coded, I have a plugin that allows me to inject php code into pages because my theme doesn’t support page templates, and therefore the problem with form actions.
Got it, thank you mate.
You can type either ‘golf’ or ‘renault’ but only the first item in my cars page appears which is ‘bmw’.
- This reply was modified 7 years, 6 months ago by halohtlo.