Function is_page() not working
-
Hello to all! Am trying to implement a filter in a specific page, but i can’t make work. Tried many variations, but no sucess. If someone could help, it would be much appreciated. The code is in functions.php. Also tried in page.php but does not work either.
The code:/* ================== Ajax Search ====================== */ function carregou_pagina(){ $id = get_the_ID(); if ( is_page( $id == 16 ) ){ //if(is_page('eventos')){ // add the ajax fetch js function ajax_fetch() { ?> <script type="text/javascript"> function fetch(){ jQuery.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', type: 'post', data: { action: 'data_fetch', keyword: jQuery('#keyword').val() }, success: function(data) { jQuery('#datafetch').html( data ); } }); } $("input#keyword").keyup(function() { if ($(this).val().length > 2) { $("#datafetch").show(); } else { $("#datafetch").hide(); } }); </script> <?php } // the ajax function function data_fetch(){ $the_query = new WP_Query( array( 'posts_per_page' => -1, 's' => esc_attr( $_POST['keyword'] ), 'post_type' => array('curso') ) ); if( $the_query->have_posts() ) : echo '<ul>'; while( $the_query->have_posts() ): $the_query->the_post(); ?> <div class="search_bar"> <form action="/" method="get" autocomplete="off"> <input type="text" name="s" placeholder="Buscar Evento..." id="keyword" class="input_search" onkeyup="fetch()"> </form> <div class="search_result" id="datafetch"> <ul> <li style="float:left;">Aguarde...</li> </ul> </div> </div> <li style="float:left;"><a>"><?php the_title(); the_post_thumbnail();?></a></li> <?php endwhile; echo '</ul>'; wp_reset_postdata(); endif; die(); } } } add_action( 'wp_loaded','carregou_pagina' ); add_action( 'wp_footer', 'ajax_fetch' ); add_action('wp_ajax_data_fetch' , 'data_fetch'); add_action('wp_ajax_nopriv_data_fetch','data_fetch'); /* ================== End Ajax Search ====================== */
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Function is_page() not working’ is closed to new replies.