Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- //console.log('ready');
- jQuery("#cbrpsearchfieldbt").click(function(){
- $("#cbrpsearchfield").keypress();
- });
- $("#cbrpsearchfield").keypress(function() {
- var cbrpsearchterm = jQuery("#cbrpsearchfield").val();
- //console.log(cbrpsearchterm);
- //console.log(cbrpsearchterm.length);
- if(cbrpsearchterm.length > 2){
- //console.log('click');
- var data = {
- action: 'cbrelatedpostajax',
- rpsearchterm:cbrpsearchterm,
- postid:<?php echo $post->ID; ?>
- };
- // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
- jQuery.post(ajaxurl, data, function(response) {
- //alert('Got this from the server: ' + response);
- jQuery('#cbrelatedpostsresult').html(response);
- });
- }
- })
- });
- </script>
- if( is_admin() )
- {
- add_action('wp_ajax_cbrelatedpostajax', 'cbrelatedpostajax_callback');
- // Load "admin-only" scripts here
- }
- function cbrelatedpostajax_callback(){
- ob_clean();
- $rpsearchterm = $_POST['rpsearchterm'] ;
- $postid = $_POST['postid'];
- $cbargs = array('post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 20, 's' => $rpsearchterm );
- $upprev_query = new WP_Query( $cbargs );
- if ($upprev_query->have_posts()) {
- while ( $upprev_query->have_posts() ) {
- $upprev_query->the_post();
- $id = get_the_ID();
- if($postid != $id )echo '<li>'.get_the_title().' - '. $id .'</li>';
- }
- }
- else echo '<li>No search result found</li>';
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement