Fejl i PHP script
Jeg har haft en udvikler via 'Freelancer' til a lave en funktion for mig, der viser tidligere indtastet overskrift på en WordPress side.Jeg skal nu have den flyttet over på en anden url, og så virker det ikke mere.
Har rettet i dette: 'url: "http://test.tester.dk/wp-admin/admin-ajax.php",'
Er der een der kan gennemskue - hvor der mere er kan ligge en oplysning.
Udvikleren er sunket i jorden ;-(
--------------
add_action('admin_head', 'my_custom_fonts'); // admin_head is a hook my_custom_fonts is a function we are adding it to the hook
function my_custom_fonts() {
echo '<style>
.search_cont{
display: block;
min-width: 100px;
height: auto;
background: #232;
box-shadow: 0 0 0 transparent;
border-radius: 4px;
border: 1px solid #7e8993;
background-color: #fff;
color: #32373c;
}
</style>';
}
// Function to render LiveChat JS code
function lh_add_livechat_js_code() {
?>
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
// alert('aaa2');
jQuery(document).ready(function($){
console.log( "aaa3" );
$('#title').after("<div class='search_cont'></div>");
$('#title').keyup(function(){
$('.search_cont').html('');
var inputText = $('#title').val();
// console.log(inputText);
// console.log(typeof(inputText));
// console.log(inputText.length);
if (inputText.length > 0) {
var addListingLink = $('a[href="post-new.php?post_type=wpbdp_listing"]');
if(addListingLink.hasClass('current')){
console.log('aaa5');
$.ajax({
url: "http://test.tester.dk/wp-admin/admin-ajax.php",
type: 'POST',
data: {
'action': 'my_user_vote2',
'inputText': inputText
},
dataType : 'json',
success: function( data ) {
console.log('aaa77');
console.log(data);
console.log(typeof(data));
$.each(data,function(index,value){
// console.log(typeof(value));
console.log(value.post_title);
$(".search_cont").append('<div class="search_item">'+value.post_title+'</div>');
// console.log('Indeks: ' + index + '; Værdi: ' + value);
});
},
compelete: function( data ) {
console.log('aaa9');
console.log(data);
},
error: function(xhr, statusText, err) {
console.log('aaa10');
// console.log(errMsg);
console.log(xhr.status);
},
done: function(data) {
console.log('aaa11');
console.log(data);
}
});
}else{
console.log('aaa6');
}
}
});
// $('li.toplevel_page_wpbdp_admin').
});
</script>
<!-- End of LiveChat code -->
<?php
}
add_action( 'admin_footer', 'lh_add_livechat_js_code' ); // For back-end
add_action( 'wp_footer', 'lh_add_livechat_js_code' ); // For front-end
add_action("wp_ajax_my_user_vote2", "my_user_vote2");
add_action("wp_ajax_nopriv_my_user_vote2", "my_user_vote2");
function my_user_vote2() {
$inputText = $_POST['inputText'];
global $wpdb;
$query = "
SELECT `post_title`
FROM `ttbz_posts`
WHERE `post_type` = 'wpbdp_listing' AND `post_status` = 'publish' AND `post_title` LIKE '%".$inputText."%'";
$result = $wpdb->get_results($query);
// $result = $titleStack;
// $result = 'aaa8';
// echo $result;
echo json_encode($result);
die();
}