AnonymousInactive
Thanks Trevor, this is very helpful!
I’ve came up with the following solution, which works when I put it in the dev console, but somehow not when I add it to the theme’s js file.
(function ( $ ) {
$svalue = $('input[name="_sf_search[]"]').val();
if($svalue != ''){
$svalue = 'תוצאות חיפוש עבור: ' + $svalue;
}else{
$svalue = "תוצאות חיפוש מתקדם";
}
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
$('.main-header h2').text( $svalue );
});
}(jQuery));
AnonymousInactive
Fair enough!
Should anyone else have the same problem: I’ve managed to find a hacky but reasonable solution for now: when parsing the drop-down contents (like turning “last_quarter” into a start and an end date) I inject some JavaScript into the document that sets the dropdown to the right value.
if (isset($_GET["_sfm_pseudofield_daterange"])) {
$daterange = $_GET["_sfm_pseudofield_daterange"];
.... Handle the date stuff
// Now remove the GET parameter so it doesn't get used as a filter and lead to 0 results
unset($_GET["_sfm_pseudofield_daterange"]);
// Use JavaScript to correctly set the dropdown again even though GET parameter was unset
add_action( 'wp_head', function() use($daterange) {
?><script>jQuery(document).ready(function(){ jQuery("[name='_sfm_pseudofield_daterange[]']").val("<?= htmlentities($daterange);?>");});</script><?
} );
}
As a feature request, it would be awesome to have a new “empty” field type (Text field, dropdown, check box, etc.) that gets passed along with the rest of the form, plus a documented interface for altering query parameters in the sf_edit_query_args
hook.
AnonymousInactive
Ahh ok, thanks. We have some script that is doing what you suggest basically. Do you think that the AJAX is failing because this script is just run on doc ready?
// Filter - add dummy end date so the hidden field works with just start date
$('.sf_date_field li:last-child input[name="_sfm_workshop_start_date[]"]').val('31/12/2040');
// If start date is empty give it today's date so it doesn't fail to load anything
var now = new Date();
var today = ('0' + (now.getMonth()+1)).slice(-2) + '/' + ('0' + now.getDate()).slice(-2) + '/' + now.getFullYear();
$( 'form.searchandfilter' ).change(function() {
$('.sf_date_field li:first-child input[name="_sfm_workshop_start_date[]"]').val(today);
});
// Add TODAY date to Filter Bar search otherwise it submits an empty value
$( '.page-id-22 .sf_date_field li:first-child input[name="_sfm_workshop_start_date[]"]').val(today);
AnonymousInactive
Yes I was! I created a ‘alphabetical-last-name’ and pass it as the ‘type’ in the query string:
if ( bp_has_members( bp_ajax_querystring( 'members' ) . $str . $qs ) ) :
And then I have a hook on bp_pre_user_query
like so:
function alphabetize_by_last_name( $bp_user_query ) {
if ( 'alphabetical-lastname' == $bp_user_query->query_vars['type'] ) {
// SELECT u.ID as id FROM wp_users u
$bp_user_query->uid_clauses['select'] = "SELECT u.ID as id FROM wp_users u LEFT JOIN wp_bp_xprofile_data xpd ON u.id = xpd.user_id";
// xpd.field_id 3 is my "last name" field in buddypress extended fields
$bp_user_query->uid_clauses['where'] = "WHERE xpd.field_id = 3";
$bp_user_query->uid_clauses['orderby'] = "ORDER by xpd.value";
$page = $bp_user_query->query_vars['page'];
if ($page) {
$offset = 20;
$limit = ( $page - 1 ) * $offset;
$bp_user_query->uid_clauses['limit'] = "LIMIT $limit, $offset";
}
}
}
add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );
AnonymousInactive
OK, first is solved, thanks a lot!
<?php
/**
* Search & Filter Pro
*
* Sample Results Template
*
* @package Search_Filter
* @author Ross Morsali
* @link http://www.designsandcode.com/
* @copyright 2015 Designs & Code
*
* Note: these templates are not full page templates, rather
* just an encaspulation of the your results loop which should
* be inserted in to other pages by using a shortcode - think
* of it as a template part
*
* This template is an absolute base example showing you what
* you can do, for more customisation see the WordPress docs
* and using template tags -
*
* http://codex.wordpress.org/Template_Tags
*
*/
if ( $query->have_posts() )
{
?>
<?php
$nPosts = 0;
while ($query->have_posts())
{
$query->the_post();
$nPosts=$nPosts+1;
$big= ($nPosts % 3);
$isNextBig=($nPosts+1)%3;
if($big=="0") echo"<br /> <div class='et_pb_column et-last-child'>";
else if($isNextBig=="0")echo"<div class='et_pb_column et_pb_column_1_2 et-last-child'>";
else echo"<div class='et_pb_column et_pb_column_1_2'>";
?>
<?php
if ( has_post_thumbnail() ) {
?>
<a>">
<div class="cont">
<div class='postimage' style='background-image: url("<?php the_post_thumbnail_url("large");?>")'></div>
<div class="overlay_post">
</div>
</div></a>
<?php
}
?>
<div class="below_image">
<h2><a>"><?php the_title(); ?></a></h2>
<?php echo do_shortcode("[yasr_visitor_votes_readonly]"); ?>
<div class="desc"><?php the_excerpt(); ?></p></div>
<p class="meta"><?php the_date();echo" | by ";?>
<a>');" href="javascript:void(0);"><?php the_author();?></a></p>
<p class="meta"><?php $categories = get_the_category();
foreach($categories as $cat){
?>
<a>slug;?>');" href="javascript:void(0);"><?php echo $cat->cat_name;?></a>
<?php
}?>
<?php $terms = get_the_terms($post->ID, "sport"); $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) {?>
<a>slug;?>');" href="javascript:void(0);"><?php echo $term->name;?></a>
<?php
} } ?></p>
<br/>
<p><a>">READ MORE</a></p>
</div>
</div>
<?php
}
}
else
{
echo "Ops! no results found!";
}
?>
<script type="text/javascript">
function searchCat(slug){
jQuery('select[name="_sft_category[]"]').val(slug).change();
}
function searchAuthor(slug){
jQuery('select[name="_sf_author[]"]').val(slug).change();
}
function searchSport(slug){
jQuery('select[name="_sft_sport[]"]').val(slug).change();
}
</script>
Hi Jesse
Just trying to get my head around this.
So, what you are trying to do is use your own search field outside of S&F, and copying the value when that gets submitted, to S&F and initiating a search?
If so my logic would simply be:
1) Copy from your search field to our search field, either on input change or submit (of your your field)
2) trigger the input update event on the field (so S&F handles the rest, it just thinks someone typed directly into its field)
I did a quick test locally, and this worked:
var $proxy_input = $('.proxy-search-input'); //this is your external search input field
$proxy_input.on("input", function(){
var val = $(this).val();
$('.searchandfilter .sf-field-search input').val(val);
$('.searchandfilter .sf-field-search input').trigger('input');
});
Let me know how you get on 🙂
AnonymousInactive
Due to layout concerns I have created a separate text input outside of the .searchandfilter form and use javascript to copy the value of that “placeholder” text field to the one inside the .searchandfilter form (“.sf-input-text”).
However, even though this function is successful at copying the value of the placeholder input to the real S&F search input, the form does not update the Auto Count function as happens when you’re actually typing in the original input.
I am using $(“.searchandfilter”).searchAndFilter(); to try and force the auto count to update but it’s not working.
Any suggestions?
var copyInput = function($proxyinput, $sfinput) {
if(window.copying == true) {
return false;
}
window.copying = true;
var $me = $proxyinput,
$myVal = $me.val();
$sfinput.val($myVal);
$sfinput.attr('value', $myVal);
var doMe = function(){
$(".searchandfilter").searchAndFilter();
window.copying = false;
}
setTimeout(doMe, 10);
},
wtgSearchProxy = function(){
// PROXY SEARCH FIELD
window.$proxyinput = $('#lib-filter--search-input');
window.$proxyinputlabel = $('#lib-filter--search-label');
window.$proxysubmit = $('#lib-filter--search-submit');
window.$sfinput = $('.sf-field-search .sf-input-text');
$proxyinput = window.$proxyinput;
$proxyinputlabel = window.$proxyinputlabel;
$proxysubmit = window.$proxysubmit;
$sfinput = window.$sfinput;
var doIt = function(){
copyInput($proxyinput, $sfinput);
};
//force search form to submit on enter
$(document).off('keyup', '#lib-filter--search-input');
$(document).on('keyup', '#lib-filter--search-input', function(e) {
copyInput($proxyinput, $sfinput);
if($proxyinput.is(':focus') && e.which == 13) {
setAjaxin();
$('.searchandfilter').submit();
return false;
}
});
This has been asked before, but I have not seen a solution, but I think others resolved it by autofilling one (hidden) field , but I do not know how. On one site I made, I used javascript to add today’s date (formatted as needed by the customer) to one field and a long away date (same customer required format) in the future to another, using this code (specific to the site):
jQuery( document ).ready(function($){
var now = new Date();
var today = ('0' + now.getDate()).slice(-2) + '/'
+ ('0' + (now.getMonth()+1)).slice(-2) + '/'
+ now.getFullYear();
jQuery('li:first-child input[name="_sfm_transportation_dummy_start_date[]"]').val(today);
jQuery('li:last-child input[name="_sfm_transportation_dummy_start_date[]"]').val('31/12/2050');
});
Because that date is so far away, that allowed the range to be used as they needed without user input. As I noted on the other thread, StackExchange is the best place to search for code snippets like this.
Hi Kai
I’ve been thinking, and there may be a slightly cleaner way to do this.
Why not, when a user clicks a category (which is before the submit & ajax is processed), clear the values of the other field and do the chosen trigger then? Rather than to do it after the submit event, and submitting again a second time?
Something along the lines of (untested):
$('.sf-field-taxonomy-download_cat input').on('change', function(){
$(".sf-field-taxonomy-download_tag .sf-input-select").val('').trigger("chosen:updated");
});
Then S&F will carry out its submit processes, and should in theory perform the search with the values you want.
Hope that helps
Thanks
AnonymousInactive
Dear Ross, thanks for checking. I understand what you mean.
The categories should be dominant for this job.
The best way I see is to kill all entries of the multibox before Ajax submit.
However, all shared tags are also deleted. :/
$(".sf-input-select").val('').trigger("chosen:updated");
Cheers!
Kai