Jump to content

jarvis

Members
  • Posts

    479
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jarvis's Achievements

Advanced Member

Advanced Member (4/5)

1

Reputation

2

Community Answers

  1. Sorted it with usort($productions, function($a1, $a2) { $v1 = strtotime($a1['year']); $v2 = strtotime($a2['year']); return $v2 - $v1; // $v2 - $v1 to reverse direction });
  2. Hi, I have a loop which creates an array: $productions[] = array( 'url'=>get_the_permalink(), 'year'=>$production_year->name, 'title'=>get_the_title() ); When I output the results, the year is in the wrong order: 2019 2018 2017 2016 2015 2014 2020 What I can't work out is how to order 2014 - 2020 I tried ksort(array, SORT_STRING) and ksort(array, SORT_NUMERIC) I also tried natsort But still have the same issue - am I missing something? Thanks
  3. @requinix Many thanks, that solved the issue! Have a great Christmas!
  4. Hi All, I hope someone can help! So I have a basic form which uses Select2. If someone uses the first field, it disables the remaining fields - this works fine. The issue is if you clear the selection in the first drop down, then pick a value from another drop down, it seems to select your choice but also adds 'Select' as an option. I've created a JS Bin to help show the issue: View the JS Bin Any help is appreciated Thanks
  5. Hi, Am hoping someone can please help. I've the following code: $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_method = explode(':', reset($chosen_methods) ); The first line returns the warning: "Warning: reset() expects parameter 1 to be array, null given in" I've tried the following: $chosen_method = ''; $chosen_method = NULL; $chosen_methods = array(); Sadly, none have worked. What am I missing? Thanks
  6. I see what you're saying but I'm still at a loss, I can see the docs but I cannot fathom how to do what I need "ajax": { "method" :"POST", "url" : '<?php echo admin_url('admin-ajax.php');?>', "data": function ( d ) { return $.extend( {action:action,tax:tax,id:id}, d, { "searchResultsHeader": $('.search-results-header').val() } ); } } ??
  7. Hi @requinix I tried to adjust example.on( 'xhr', function ( e, settings, json ) {// check is the response is not null and show the table if (json != null) { $('#example').removeClass("hide-me",""); jQuery(".search-results-header").html(data); } } ); I also tried adding d.search-results-header = $('#search-results-header').val(); Into the render part of the code I'll be honest, I'm struggling to make sense of it, hence turning to this forum for assistance. I'd previously read the link you sent and struggled to make sense of it. I also Google'd for examples, hence basing my code on someone else's example and adapting to my requirements. Less than ideal I know but got my code working. A lot of examples I found were using GET whereas I needed POST. Thanks
  8. Thanks @requinix When I previously tried ajaxifying the content, the search on the table didn't work. The code above worked and still enables the search functionality I just can't quite see how to do/integrate the other part
  9. @requinix I was going aiming to to insert it into that div. So table content goes to table and additional info to here. Or is it better to do it another way?
  10. Hi All, I use a jQuery datatable to display information from a search. The results are posted back via Ajax to a default table placeholder like so: <table id="example" class="table table-striped table-responsive hide-me" style="width:100%"> <thead> <tr> <th>Sponsor</th> <th>Nationality</th> <th>Sector</th> <th>Team Sponsored</th> <th>Sport</th> </tr> </thead> <tfoot> <tr> <th>Sponsor</th> <th>Nationality</th> <th>Sector</th> <th>Team Sponsored</th> <th>Sport</th> </tr> </tfoot> </table> This is handled by the following: $(document).on('click', '.taxonomy-sponsor-link', function(){ var action = 'get_sponsors_by_taxonomy'; var id = $(this).data('id'); var tax = $(this).data('tax'); //alert('action: '+action+' tax: '+tax+' id: '+id); //assing the datatable call to a variable let example = $('#example').DataTable({ "destroy": true, "responsive":{//this is usefull if you want to use a full responsive datatable just add the responsive css from dataTables.net "details": { renderer: function ( api, rowIdx, columns ) { var data = $.map( columns, function ( col, i ) { return col.hidden ? '<tr data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+ '<td>'+col.title+':'+'</td> '+ '<td>'+col.data+'</td>'+ '</tr>' : ''; } ).join(''); return data ?$('<table/>').append( data ) :false; } } }, "autoWidth": false,//fix Bootstrap 4 glitch "ajax": { method :"POST", url : '<?php echo admin_url('admin-ajax.php');?>', data : {action:action,tax:tax,id:id,}, }, "columns": [ {"data": "sponsor"}, {"data": "nationality"}, {"data": "sector"}, {"data": "team_sponsored"}, {"data": "sport"} ], "columnDefs": [ { //"className": "dt-center", "targets": "_all" "className": "", "targets": "_all" } ] }); example.on( 'xhr', function ( e, settings, json ) {// check is the response is not null and show the table if (json != null) { $('#example').removeClass("hide-me",""); } } ); }); And my PHP gathers the data and passes it back via: echo json_encode($json); What I'd like to do, is also pass 1 other value from the results but not in the table. So wanted to use something like: <div id="search-results-header"></div> After an bit of searching, I can see you can alter the json_encode to be an array, so something like: echo json_encode(array( 'example' => $json, 'search-results-header' => $search )); However, I then can't work out whether: a) This is correct b) How I adjust the above call to output the table results AND the additional parameter. I wonder if someone would be kind enough to please assist? Thanks
  11. Thanks @requinix Unfortunately, this stems from a Wordpress build and the code is generated by a plugin, so its beyond my control.
  12. HI All, I'm hoping someone can help! I need to either remove or change a DIV tag directly above another. Here's the code: <div style="clear:both;"></div> <div class="berocket_lgv_widget" style="float:left;padding: 5px 0px 5px 0px;"> Either the entire first DIV needs removing or change the style to clear:none I thought something like: $(".berocket_lgv_widget").prev().attr("style", " clear:none"); $(".berocket_lgv_widget").prev().remove(); No joy with either. I also tried before() Any help is much appreciated Thanks
  13. Apologies, why is it by posting I managed to work these things out Each of my posts when created gets the company ID assigned. So rather than query post by author ID, I queried for all posts linked by company ID This worked! More so because the tests I were doing were based on posts written by the primary user ID, not any other user IDs with the same company ID Problem solved!
  14. Hi All, I really hope someone can help me on this. Basically, I'm trying to disable a bunch of accounts linked by a custom field value of company_id. It toggles a custom field of enable_account from 1 to 0 - this part works fine. What I also need to do, is once the user is disabled, locate any posts by the user (author ID) and set it from publish to draft. Now, this is oddly the part not working! If I dump the code out in any file its fine, however, once I put the exact code back to my functions file, it fails. So I have the disable link on a template like so: <a href="#" data-id="<?php echo $user_info->ID; ?>" data-nonce="<?php echo wp_create_nonce('my_disable_account_nonce') ?>" class="disable-account">Disable</a> It s handled by this: $('.disable-account').click(function(){ if (confirm('Are you sure you want to disable this account?')) { var action = 'disable_account'; var id = $(this).data('id'); var nonce = $(this).data('nonce'); //alert('ID: '+id+' Nonce: '+nonce); $.ajax({ type : "POST", data : { action:action, id:id, nonce:nonce}, dataType : "html", url : '<?php echo admin_url('admin-ajax.php');?>', success : function(data) { //alert(this.data); jQuery("#table_data").html(data); console.log("action:" + action + " id: " + id + " nonce: " + nonce); //debug //window.location.reload(); }, error : function(xhr, status, error) { var err = eval("(" + xhr.responseText + ")"); alert(err.Message); } }); } }); Finally, here's the function: function disable_account() { $permission = check_ajax_referer( 'my_disable_account_nonce', 'nonce', false ); if( $permission == false ) { echo '<td colspan="7">Error!</td>'; } else { $response = ''; // Get the company ID $company_id = get_field( 'company_id', 'user_'.$_REQUEST['id'] ); $response .= '<p>Company ID: '.$company_id.'</p>'; // Update the main user update_user_meta( $_REQUEST['id'], 'enable_account', '0' ); $response .= '<p>Primary User ID: '.$_REQUEST['id'].'</p>'; $user_args = array( 'role__in' => array('subscriber', 'staff_member'), 'orderby' => 'meta_value', 'meta_key' => 'company_name', 'order' => 'ASC', 'meta_query'=> array( array( 'relation' => 'AND', # OR array( 'key' => 'enable_account', 'value' => '1', 'compare' => "=", ), array( 'key' => 'company_id', 'value' => $company_id, 'compare' => "=", ) ) ) ); $users = get_users( $user_args ); if ($users): foreach ( $users as $user ) : $user_info = get_userdata( $user->ID ); // Update the main user update_user_meta( $user->ID, 'enable_account', '0' ); #echo '<p>User ID: '.$user->ID.'</p>'; $response .= '<p>User ID: '.$user->ID.'</p>'; global $post; // Get all posts by author ID $myposts = get_posts( array( 'post_status' => 'publish', 'posts_per_page'=> -1, 'author' => $user->ID )); if ( $myposts ) { foreach ( $myposts as $post ) : setup_postdata( $post ); $response .= '<p>Post ID: '.$post->ID.'</p>'; endforeach; wp_reset_postdata(); } endforeach; else: endif; echo $response; } die(); } // Fire AJAX action for logged in users only add_action('wp_ajax_disable_account', 'disable_account'); As I say, using this in an ordinary template works. For now, I've removed the code to change the post from publish to draft as at this stage, its not even displaying the Post ID, so I know its not even getting this far! Have I missed something obvious? Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.