Jump to content

samoht

Members
  • Posts

    421
  • Joined

  • Last visited

Everything posted by samoht

  1. I fixed my JSON. I should not have been double encoding so it now looks like this: { "page": 1, "total_pages": 2, "sermons": [ { "ID": "165", "post_author": "1", "post_date": "2014-01-29 10:45:00", "post_date_gmt": "2014-01-29 21:06:20", "post_content": "The gospel grammar of the New Testament is not new - but perfectly structured in the judgment oracle against Philistia. In the final verse the great apologetic question, \"what shall one tell...\" is answered with both the indicative (The Lord has founded Zion) and the imperative (the afflicted of His people shall rest in it). This is the essential Q&A of all life!", "post_title": "The Lord Has Founded Zion", "post_excerpt": "", "post_status": "publish", "comment_status": "open", "ping_status": "open", "post_password": "", "post_name": "the-lord-has-founded-zion", "to_ping": "", "pinged": "", "post_modified": "2014-01-29 10:45:00", "post_modified_gmt": "2014-07-01 19:07:13", "post_content_filtered": "", "post_parent": "0", "guid": "http://localhost/newomega/?post_type=mbsb_sermon&p=165", "menu_order": "0", "post_type": "mbsb_sermon", "post_mime_type": "", "comment_count": "0" }, { "ID": "287", "post_author": "1", "post_date": "2014-06-29 10:45:00", "post_date_gmt": "2014-06-29 10:45:00", "post_content": "Isaiah begins his conclusion to the book of the king with an historical narrative that demonstrates the certainty and trustworthy nature of God's Word. ", "post_title": "In Whom Are You Trusting", "post_excerpt": "", "post_status": "publish", "comment_status": "open", "ping_status": "closed", "post_password": "", "post_name": "in-whom-are-you-trusting", "to_ping": "", "pinged": "", "post_modified": "2014-06-29 10:45:00", "post_modified_gmt": "2014-06-29 10:45:00", "post_content_filtered": "", "post_parent": "0", "guid": "http://localhost/newomega/?post_type=mbsb_sermon&p=287", "menu_order": "0", "post_type": "mbsb_sermon", "post_mime_type": "", "comment_count": "0" } ] } which is still valid JSON and is still giving me the SyntaxError : Unexpected token < I don't see where that could be coming from?
  2. ok I changed my PHP function to this: $serms = json_encode($sermons); $return = json_encode(array('page' => $paged, 'total_pages' => $max_num_pages, 'sermons' => $serms )); which spits out: { "page": 1, "total_pages": 2, "sermons": "[{\"ID\":\"165\",\"post_author\":\"1\",\"post_date\":\"2014-01-29 10:45:00\",\"post_date_gmt\":\"2014-01-29 21:06:20\",\"post_content\":\"The gospel grammar of the New Testament is not new - but perfectly structured in the judgment oracle against Philistia. In the final verse the great apologetic question, \\\"what shall one tell...\\\" is answered with both the indicative (The Lord has founded Zion) and the imperative (the afflicted of His people shall rest in it). This is the essential Q&A of all life!\",\"post_title\":\"The Lord Has Founded Zion\",\"post_excerpt\":\"\",\"post_status\":\"publish\",\"comment_status\":\"open\",\"ping_status\":\"open\",\"post_password\":\"\",\"post_name\":\"the-lord-has-founded-zion\",\"to_ping\":\"\",\"pinged\":\"\",\"post_modified\":\"2014-01-29 10:45:00\",\"post_modified_gmt\":\"2014-07-01 19:07:13\",\"post_content_filtered\":\"\",\"post_parent\":\"0\",\"guid\":\"http:\\/\\/localhost\\/newomega\\/?post_type=mbsb_sermon&p=165\",\"menu_order\":\"0\",\"post_type\":\"mbsb_sermon\",\"post_mime_type\":\"\",\"comment_count\":\"0\"},{\"ID\":\"287\",\"post_author\":\"1\",\"post_date\":\"2014-06-29 10:45:00\",\"post_date_gmt\":\"2014-06-29 10:45:00\",\"post_content\":\"Isaiah begins his conclusion to the book of the king with an historical narrative that demonstrates the certainty and trustworthy nature of God's Word. \",\"post_title\":\"In Whom Are You Trusting\",\"post_excerpt\":\"\",\"post_status\":\"publish\",\"comment_status\":\"open\",\"ping_status\":\"closed\",\"post_password\":\"\",\"post_name\":\"in-whom-are-you-trusting\",\"to_ping\":\"\",\"pinged\":\"\",\"post_modified\":\"2014-06-29 10:45:00\",\"post_modified_gmt\":\"2014-06-29 10:45:00\",\"post_content_filtered\":\"\",\"post_parent\":\"0\",\"guid\":\"http:\\/\\/localhost\\/newomega\\/?post_type=mbsb_sermon&p=287\",\"menu_order\":\"0\",\"post_type\":\"mbsb_sermon\",\"post_mime_type\":\"\",\"comment_count\":\"0\"}]" } I ran that through a json validator and it came back valid JSON So I know I giving my AJAX response valid JSON but it still is choking. My length is a much more respectable 6382 but I get Uncaught SyntaxError: Unexpected token < How can I get a SyntaxError if my JSON is valid?
  3. Also, If I just return the db query like $return = json_encode($sermons); then I get a length of 1752 and the log spits out the titles as expected ??
  4. Thanks for you patience with me. This is what I have changed my PHP function to look like to send JSON data back to my ajax if($_POST['meta_key']){ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $mk = '"'.$_POST['meta_key'].'"'; $mv = intval($_POST['meta_value']); $ppp = intval($_POST['posts_per_page']); $offset = ($paged - 1) * $ppp; $sermons = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS sermons.* FROM {$wpdb->prefix}posts AS sermons, {$wpdb->prefix}postmeta WHERE meta_key = {$mk} AND meta_value = {$mv} AND sermons.ID = {$wpdb->prefix}postmeta.post_id LIMIT {$offset}, {$ppp}", OBJECT); $sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" ); $max_num_pages = ceil($sql_posts_total / $ppp); $return = json_encode(array('page': $paged, 'total_pages': $max_num_pages, 'sermons': $sermons)); echo $return; exit; } I believe that this is sending back the multi-dimesional array with all the data I requested, but now I do not know how to parse that to populate my page or the navigation? I assume that I need to loop with .each? $.post(mbsb_ajaxurl, data, function(response) { console.log(response.length); $.each($.parseJSON(response), function(idx, obj) { console.log(obj.post_title); //$('.main_title').html(obj.post_title); }); }); but this returns a length of 187 (seems a little low? but it could be right) and a Uncaught SyntaxError: Unexpected token < I guess that means my JSON array is not correct?
  5. I see. Sorry for the misunderstanding. That is why you started with $return = array (... I am still a little foggy on how this would work with populating the page and the links. For example: you said 'page' => 2, at the beginning of your example array. I'm not sure where the 2 would come from. Would that be a php variable passed into the return array or would it be derived from somewhere else? Again, forgive me if I am missing the obvious. Thanks,
  6. Sorry the above code has an error in it, I knew it was there but posted to soon and it would not let me edit? Anyway the error is $('#pagination').load(lp); on line 133 But I removed that and still no luck. Am I correct in thinking that I should have an on click event for the link to be sure I serve up the correct paginated content? Otherwise it would just default to the normal php page right??
  7. Well I tried something else which I thought would work, but not so much. I added another ajax call to load the pagelinks //Listen for the menu's to change except the main filter_by dropdown var ids = ['filter_preacher_dropdown', 'filter_sort_by_dropdown', 'filter_per_page_dropdown', 'filter_series_dropdown', 'filter_service_dropdown', 'filter_tag_dropdown', 'filter_book_dropdown', 'filter_year_dropdown']; $('#' + ids.join(',#')).change(function(e) { var pt = [ "preacher","series","service" ]; if($.inArray(this.name, pt)!==-1){ var mk = this.name; var mv = $(this).val(); var ppp = $("#filter_per_page_dropdown").val(); var ob = $("#filter_sort_by_dropdown").val(); var lp = $(location).attr('href'); var data = { action: 'filter_sermons', meta_key: mk, meta_value: mv, posts_per_page: ppp, linkpage: lp }; $.post(mbsb_ajaxurl, data, function(response) { $('#sermonlists').fadeOut('slow', function() { $(this).html(response); $('#pagination').load(lp); }).fadeIn('slow'); }); } }); //NEW AJAX call for pagelinks $('#pagination').on('click', '#pag-link > li > a', function(){ var link = $(this).attr('href'); $.ajax({ url: $location().attr('href'), type:'GET', dataType: 'json', success: function(listings){ $('#pagination').html(listings); } // End of success function of ajax form }); // End of ajax call return false; }); but that just filled my #pagination div with the entire page again?
  8. Thanks Psycho, forgive me for this probably dumb question, but are you saying skip the php function all together?
  9. Hello all, I feel pretty good that I got my AJAX filter working properly. But it still needs some help. Now I am returning the content with Ajax that I want from the search filter of dropdown option (keep in mind there are several options to filter by). But the content returned is often to much to fit on one page - so I need to paginate the successfully returned html from my AJAX call. Here is where I get stumped. Do I setup a normal page nav outside the AJAX area? </div><!-- AJAX return container--> <nav class="pagenav"> <ul id="pag-link"> <li class="old"><?php next_posts_link('« Older Sermons', $sermons_query->max_num_pages) ?></li> <li class="new"><?php previous_posts_link('Newer Sermons »', $sermons_query->max_num_pages) ?></li> </ul> </nav> IF so, how do I update the links info? or do I keep the page nav inside the AJAX area but use some custom code to retrieve the proper link? (I tried using the normal wordpress page nav functions in my php function but they provide the url of the page that the php function is on, not the actual page being viewed). Do I need to make a separate AJAX call to a function that just builds my links? or is there a way to do it with my main call? Here is my AJAX call: //Listen for the menu's to change except the main filter_by dropdown var ids = ['filter_preacher_dropdown', 'filter_sort_by_dropdown', 'filter_per_page_dropdown', 'filter_series_dropdown', 'filter_service_dropdown', 'filter_tag_dropdown', 'filter_book_dropdown', 'filter_year_dropdown']; $('#' + ids.join(',#')).change(function(e) { var pt = [ "preacher","series","service" ]; if($.inArray(this.name, pt)!==-1){ var mk = this.name; var mv = $(this).val(); var ppp = $("#filter_per_page_dropdown").val(); var ob = $("#filter_sort_by_dropdown").val(); var data = { action: 'filter_sermons', meta_key: mk, meta_value: mv, posts_per_page: ppp }; $.post(mbsb_ajaxurl, data, function(response) { $('#sermonlists').fadeOut('slow', function() { $(this).html(response) }).fadeIn('slow'); }); } and here is my php function (slightly paired down for viewing ease): //ajax for sermons filter add_action('wp_ajax_filter_sermons', 'check_ajax'); add_action('wp_ajax_nopriv_filter_sermons', 'check_ajax'); function check_ajax() { global $wpdb, $paged, $max_num_pages; //check if filter is on post_type if($_POST['meta_key']){ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $mk = '"'.$_POST['meta_key'].'"'; $mv = intval($_POST['meta_value']); $ppp = intval($_POST['posts_per_page']); $offset = ($paged - 1) * $ppp; $sermons = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS sermons.* FROM {$wpdb->prefix}posts AS sermons, {$wpdb->prefix}postmeta WHERE meta_key = {$mk} AND meta_value = {$mv} AND sermons.ID = {$wpdb->prefix}postmeta.post_id LIMIT {$offset}, {$ppp}", OBJECT); $sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" ); $max_num_pages = ceil($sql_posts_total / $ppp); }elseif($_POST['name']){ //another custom query }elseif ($_POST['book_number']){ //another custom query } $posts = get_posts(); // returns posts in an array if($sermons) { global $post; foreach ($sermons as $post){ setup_postdata($post); //custom query info returned here } //Would the Pagination for the AJAXED content go here? }else{ ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php } die(); }
  10. yes, That just returned POST http://localhost/newomega/wp-admin/admin-ajax.php net::ERR_CONNECTION_RESET
  11. I realized that I had the check_ajax() function in the wrong place. So I moved it and the calls to it, and now I have the AJAX working (I think) - but the problem is what I am returning. function check_ajax() { $mk = '"'.$_POST['meta_key'].'"'; $mv = intval($_POST['meta_value']); $ppp = intval($_POST['posts_per_page']); $query = new WP_Query( array( 'meta_key' => $mk, 'meta_value' => $mv, 'post_type' => 'mbsb_sermon', 'posts_per_page' => $ppp ) ); $posts = get_posts(); // returns posts in an array echo json_encode($posts); die(); } returns [] while echo json_encode($query); returns {"query":{"meta_key":"\"preacher\"","meta_value":365,"post_type":"mbsb_sermon","posts_per_page":0},"query_vars":{"meta_key":"\"preacher\"","meta_value":365,"post_type":"mbsb_sermon","posts_per_page":10,"error":"","m":"","p":0,"post_parent":"","subpost":"","subpost_id":"","attachment":"","attachment_id":0,"name":"","static":"","pagename":"","page_id":0,"second":"","minute":"","hour":"","day":0,"monthnum":0,"year":0,"w":0,"category_name":"","tag":"","cat":"","tag_id":"","author":"","author_name":"","feed":"","tb":"","paged":0,"comments_popup":"","preview":"","s":"","sentence":"","fields":"","menu_order":"","category__in":[],"category__not_in":[],"category__and":[],"post__in":[],"post__not_in":[],"tag__in":[],"tag__not_in":[],"tag__and":[],"tag_slug__in":[],"tag_slug__and":[],"post_parent__in":[],"post_parent__not_in":[],"author__in":[],"author__not_in":[],"ignore_sticky_posts":false,"suppress_filters":false,"cache_results":true,"update_post_term_cache":true,"update_post_meta_cache":true,"nopaging":false,"comments_per_page":"50","no_found_rows":false,"order":"DESC"},"tax_query":{"queries":[],"relation":"AND"},"meta_query":{"queries":[{"key":"\"preacher\"","value":365}],"relation":"AND"},"date_query":false,"request":"SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'mbsb_sermon' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending') AND ( (wp_postmeta.meta_key = '\\\"preacher\\\"' AND CAST(wp_postmeta.meta_value AS CHAR) = '365') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10","posts":[],"post_count":0,"current_post":-1,"in_the_loop":false,"comment_count":0,"current_comment":-1,"found_posts":0,"max_num_pages":0,"max_num_comment_pages":0,"is_single":false,"is_preview":false,"is_page":false,"is_archive":true,"is_date":false,"is_year":false,"is_month":false,"is_day":false,"is_time":false,"is_author":false,"is_category":false,"is_tag":false,"is_tax":false,"is_search":false,"is_feed":false,"is_comment_feed":false,"is_trackback":false,"is_home":false,"is_404":false,"is_comments_popup":false,"is_paged":false,"is_admin":true,"is_attachment":false,"is_singular":false,"is_robots":false,"is_posts_page":false,"is_post_type_archive":true,"thumbnails_cached":false}
  12. Still no page change? Do I have to use my_sermon_query() on the main page? or does check_ajax() take care of that? I think I am missing only a small piece - but its still stopping the works. I have a main page (small-sermons.php) that queries the WPDB for all posts with the custom post_type=mbsb_sermon On that page I have included a form that allows the users to filter/search based on series, preacher, service - which are all custom post_types themselves. So I have a JQuery/Ajax call (frontend.js) that fires when those dropdowns change so I can handle resetting the query with the new parameters by sending the results to a custom function (functions.php) check_ajax(). I seem to be getting the right variables in the $_POST object to create the proper query for the search - but its not updating the page with the new query??
  13. I slightly rewrote the ajax and now I do get a return on the console $.ajax ( { type: "POST", url: ajax_object.ajaxurl, data: {action: 'filter_sermons', meta_key: mk, meta_value: mv, post_per_page: ppp}, success: function(data){ console.log(data); } } ); but still nothing is happening on the page?
  14. OK, thanks for the help understanding but I am not quite there. So the AJAX is ok? ( I changed the php function as noted but I still get 0 on the console log ) If so does that mean I just need to call the function from my page as the main query? $query = check_ajax(); ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?> that doesn't seem right, because I have no default posts until the filter by or do I put the while loop for the posts in the check_ajax() function?
  15. Thanks Guru, But if I use 'results' I either get undefined - or I get 0 again?? data: { action: 'filter_sermons', meta_key: mk, meta_value: mv }, dataType: 'JSON', success:function(data){ console.log(results); } Gets me an Uncaught ReferenceError: results is not defined and data: { action: 'filter_sermons', meta_key: mk, meta_value: mv }, dataType: 'JSON', success:function(results){ console.log(results); } gets me a 0 ??
  16. hello all, I am trying to use ajax, to filter my custom post_type using a dropdown (several actually, but just working on one now). when I check the console.log for my two variables the log returns the values that I need to pass into my function check_ajax() I am using to do the filtering, but when I check the log for the data array it comes up with 0? Here is my Jquery code: //Listen for the menu's to change except the main filter_by dropdown var ids = ['filter_preacher_dropdown', 'filter_sort_by_dropdown', 'filter_per_page_dropdown', 'filter_series_dropdown', 'filter_tag_dropdown', 'filter_book_dropdown', 'filter_year_dropdown']; $('#' + ids.join(',#')).change(function() { var sermonForm = $("#sermon_filter_form"); var myForm = $(this).closest("form"); var meta_key = this.name; var meta_value = $(this).val(); var current_selection = $(this); var ajaxLoader = '<div class="loading_img"></div>'; $(this).after(ajaxLoader); $.ajax ( { type: "POST", url: ajax_object.ajax_url, data: { 'action': 'filter_sermons', 'meta_key': meta_key, 'meta_value': meta_value, }, dataType: 'JSON', success:function(data){ console.log(data); } } ); }); and here is my function.php code: //ajax for sermons filter add_action('wp_ajax_filter_sermons', 'check_ajax'); add_action('wp_ajax_nopriv_filter_sermons', 'check_ajax'); } /** * Sets up custom query for AJAX to filter * */ function my_sermon_query($meta_key, $meta_value) { return new WP_Query( array( 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'post_type' => 'mbsb_sermon' ) ); } function check_ajax() { $mk = intval($_POST['meta_key']); $mv = intval($_POST['meta_value']); $query = my_sermon_query($mk, $mv); echo json_encode($query); die(); } Any ideas what I am missing/doing wrong? Thanks,
  17. OK, so maybe this would need to be an AJAX operation or onClick event of some sort??? I'm not really sure though because I want to store the data retrieved?? Any ideas? Thanks,
  18. Hello, I have been looking for a way to track the play stats on audio mp3's in the admin of my custom post-type. Whatever I google seems to come up with nothing. I not very versed in audio player code - could someone please point me in the right direction. Again: I have a custom post-type which uses the wordpress default audio. I would like to get the number of plays for each audio file and display that in the admin column for my custom post-type Thanks, Drew
  19. Thanks for the reply. I'm not sure what is missing though? Do you see something obvious?
  20. Hello all, I am trying to chase down an error thrown by timthumb.php I get this error: however A TimThumb error has occured The following error(s) occured: Could not find the internal image you specified. Query String : src=http://omegaopc.org/wp-content/connection_images/dillon_original.jpg&h=54&w=80&zc=2 TimThumb version : 2.8.11 however, the url source without the resize info (http://omegaopc.org/wp-content/connection_images/dillon_original.jpg) loads just fine. I have set the permissions on the connection_images folder to 755 as well as on timthumb.php I have heard this error comes from a permissions issue - but I can't find where else a permissions restriction would be? Any ideas how to track this down?
  21. I have a directory that I would like to allow users to print to PDF format for download. How can I do this and where do I start?
  22. hello all, I have been Googling for a bit and have not found a good tut or place to start with adding or updating events on my google calendar from a web form. There should be a ton of tuts on this kind of thing but I can't find them. Any idea where to start? Here is what my php web form collects: Name, email, date (this is a future date the user is signing up for), notes The Form has a title: Craft and Lesson Schedule Which I would like to show on the gcal as the event name. I did see something about using php and Zend <?php // load classes require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); Zend_Loader::loadClass('Zend_Http_Client'); // connect to service $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $user = "username@gmail.com"; $pass = "pass"; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); $gcal = new Zend_Gdata_Calendar($client); // validate input if (empty($_POST['title'])) { die('ERROR: Missing title'); } if (!checkdate($_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy'])) { die('ERROR: Invalid start date/time'); } if (!checkdate($_POST['edate_mm'], $_POST['edate_dd'], $_POST['edate_yy'])) { die('ERROR: Invalid end date/time'); } $title = htmlentities($_POST['title']); $start = date(DATE_ATOM, mktime($_POST['sdate_hh'], $_POST['sdate_ii'], 0, $_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy'])); $end = date(DATE_ATOM, mktime($_POST['edate_hh'], $_POST['edate_ii'], 0, $_POST['edate_mm'], $_POST['edate_dd'], $_POST['edate_yy'])); // construct event object // save to server try { $event = $gcal->newEventEntry(); $event->title = $gcal->newTitle($title); $when = $gcal->newWhen(); $when->startTime = $start; $when->endTime = $end; $event->when = array($when); $gcal->insertEvent($event); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getResponse(); } echo 'Event successfully added!'; } ?> however, this looked out of date?
  23. So, I got it to work sort of! I removed the relative link and for some reason that worked. So then I tried just shortening the relative link to <a href="?book='.rawurlencode($book->book_name).'">' Which also worked. - not sure why adding the /bible/ in front of the query broke it?
  24. ok, I am trying rawurlencode() now and it is writing in the %20 then ON the page reload when I get the variable from the url I am using rawurldecode() but the space is still being removed before I run my query?? <?php if($_GET['book'] == ''){ $books = $wpdb->get_results(" SELECT book_name FROM {$wpdb->prefix}sb_books_sermons LEFT JOIN {$wpdb->prefix}sb_books ON {$wpdb->prefix}sb_books_sermons.book_name = name GROUP BY book_name ORDER BY {$wpdb->prefix}sb_books.id ASC "); foreach($books as $book){ echo '<li><div class="droidlist"><a href="bible/?book='.htmlentities(rawurlencode($book->book_name)).'">'.$book->book_name.'</a></div></li>'."\n\t"; } }else { $book = $wpdb->escape(rawurldecode($_GET['book']));
  25. Thanks, but when I use urlencode() it adds a '+' where the white space is (all good) - which is then removed in the url after I click the link? I assume I need to use urldecode() - but where?? is my .htaccess rewriting the url?
×
×
  • 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.