Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('init', 'my_setcookie');
- // my_setcookie() set the cookie on the domain and directory WP is installed on
- function my_setcookie(){
- $path = parse_url(get_option('siteurl'), PHP_URL_PATH);
- $host = parse_url(get_option('siteurl'), PHP_URL_HOST);
- $expiry = strtotime('+1 month');
- setcookie('my_cookie', 'default_string', $expiry, $path, $host);
- }
- function searchAdvertisements() {
- header('Content-Type: application/html;charset=utf-8');
- $text = $_POST['searchText'];
- global $wpdb;
- $myposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts
- WHERE post_type = 'advertisements'
- AND post_title != 'Automatický koncept'
- and post_title LIKE '%s'", '%'. $wpdb->esc_like( $text ) .'%') );
- $arrayID = array();
- foreach ($myposts as $post) {
- array_push($arrayID, $post->ID);
- }
- // rewrite cookie, new value will be used in custom page
- setcookie('my_cookie_name_1', $arrayID, get_page_link(45), get_page_link(45));
- $postArray = [];
- array_push($postArray, get_page_link(45));
- array_push($postArray, $text);
- array_push($postArray,$arrayID);
- echo json_encode($postArray);
- wp_reset_query();
- wp_die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement