dynamisches suchfeld eingefügt - nocht
erstelle mit claude 4.5 - die auswahlfunktion funktioniert aber nicht das absenden nach dem auswählen in den beitrag hinein. -> "Block rendering failed"
This commit is contained in:
parent
9341afa1dc
commit
7437d10019
3 changed files with 161 additions and 26 deletions
|
|
@ -29,14 +29,14 @@ $image_size_options['full'] = 'Full';
|
|||
?>
|
||||
|
||||
<div class="tnp-field-row">
|
||||
<div class="tnp-field-col-3">
|
||||
<div class="tnp-field-col-2">
|
||||
<label for="post-search-input"><?php _e('Search by post title', 'advanced-composer-blocks-for-newsletter') ?></label>
|
||||
<input type="text" id="post-search-input" placeholder="<?php _e('Type to search posts...', 'advanced-composer-blocks-for-newsletter') ?>" />
|
||||
<div id="post-search-results" style="display: none; position: relative; z-index: 1000; background: white; border: 1px solid #ccc; max-height: 200px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
<div class="tnp-field-col-2">
|
||||
<?php $fields->text('post_id', __('Post ID', 'advanced-composer-blocks-for-newsletter')) ?>
|
||||
</div>
|
||||
<div class="tnp-field-col-3">
|
||||
|
||||
</div>
|
||||
<div class="tnp-field-col-3">
|
||||
|
||||
<small><?php _e('Or enter Post ID manually', 'advanced-composer-blocks-for-newsletter') ?></small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -242,6 +242,78 @@ jQuery(document).ready(function($){
|
|||
$('#tnpc-block-options').hover(function(){
|
||||
mbtnp_post_list_visibility();
|
||||
});
|
||||
|
||||
// Post title search functionality
|
||||
var searchTimeout;
|
||||
var ajaxUrl = typeof ajaxurl !== 'undefined' ? ajaxurl : '<?php echo admin_url("admin-ajax.php"); ?>';
|
||||
|
||||
$('#post-search-input').on('keyup', function() {
|
||||
var searchTerm = $(this).val();
|
||||
var $results = $('#post-search-results');
|
||||
|
||||
if (searchTerm.length < 2) {
|
||||
$results.hide().empty();
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(function() {
|
||||
console.log('Sending AJAX request with:', {
|
||||
action: 'mbtnp_search_posts',
|
||||
search_term: searchTerm,
|
||||
url: ajaxUrl
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: ajaxUrl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'mbtnp_search_posts',
|
||||
search_term: searchTerm
|
||||
},
|
||||
success: function(response) {
|
||||
console.log('AJAX Success:', response);
|
||||
if (response.success && response.data.length > 0) {
|
||||
var html = '';
|
||||
$.each(response.data, function(index, post) {
|
||||
html += '<div class="post-search-result" data-post-id="' + post.ID + '" style="padding: 8px; cursor: pointer; border-bottom: 1px solid #eee;">';
|
||||
html += '<strong>' + post.post_title + '</strong><br>';
|
||||
html += '<small>ID: ' + post.ID + ' | ' + post.post_date + ' | ' + post.post_type + '</small>';
|
||||
html += '</div>';
|
||||
});
|
||||
$results.html(html).show();
|
||||
} else {
|
||||
$results.html('<div style="padding: 8px; color: #666;"><?php _e("No posts found", "advanced-composer-blocks-for-newsletter") ?></div>').show();
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
console.error('AJAX Error:', textStatus, errorThrown);
|
||||
console.error('Response:', jqXHR.responseText);
|
||||
$results.html('<div style="padding: 8px; color: #d63638;"><?php _e("Search failed", "advanced-composer-blocks-for-newsletter") ?></div>').show();
|
||||
}
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// Handle click on search results
|
||||
$(document).on('click', '.post-search-result', function() {
|
||||
var postId = $(this).data('post-id');
|
||||
var postTitle = $(this).find('strong').text();
|
||||
|
||||
$('#options-post_id').val(postId);
|
||||
$('#post-search-input').val(postTitle);
|
||||
$('#post-search-results').hide();
|
||||
|
||||
// Trigger change event to update preview
|
||||
$('#options-post_id').trigger('change');
|
||||
});
|
||||
|
||||
// Hide search results when clicking outside
|
||||
$(document).on('click', function(event) {
|
||||
if (!$(event.target).closest('#post-search-input, #post-search-results').length) {
|
||||
$('#post-search-results').hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue