Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. add_action('init', 'my_setcookie');
  2.  
  3. // my_setcookie() set the cookie on the domain and directory WP is installed on
  4. function my_setcookie(){
  5. $path = parse_url(get_option('siteurl'), PHP_URL_PATH);
  6. $host = parse_url(get_option('siteurl'), PHP_URL_HOST);
  7. $expiry = strtotime('+1 month');
  8. setcookie('my_cookie', 'default_string', $expiry, $path, $host);
  9. }
  10.  
  11. function searchAdvertisements() {
  12. header('Content-Type: application/html;charset=utf-8');
  13.  
  14. $text = $_POST['searchText'];
  15.  
  16. global $wpdb;
  17. $myposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts
  18. WHERE post_type = 'advertisements'
  19. AND post_title != 'Automatický koncept'
  20. and post_title LIKE '%s'", '%'. $wpdb->esc_like( $text ) .'%') );
  21.  
  22. $arrayID = array();
  23.  
  24. foreach ($myposts as $post) {
  25. array_push($arrayID, $post->ID);
  26. }
  27.  
  28. // rewrite cookie, new value will be used in custom page
  29. setcookie('my_cookie_name_1', $arrayID, get_page_link(45), get_page_link(45));
  30.  
  31. $postArray = [];
  32. array_push($postArray, get_page_link(45));
  33. array_push($postArray, $text);
  34. array_push($postArray,$arrayID);
  35.  
  36. echo json_encode($postArray);
  37.  
  38. wp_reset_query();
  39. wp_die();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement