ajax stopped working when not logged in wordpress

Try to output the debug query Find fragment $the_query = new WP_Query( array( ‘posts_per_page’ => 5, ‘s’ => esc_attr( $_POST[‘keyword’] ) ) ); if( $the_query->have_posts() ) : Replaced by $the_query = new WP_Query( array( ‘posts_per_page’ => 5, ‘s’ => esc_attr( $_POST[‘keyword’] ) ) ); echo (string)$the_query->request; if( $the_query->have_posts() ) : Perhaps some hooks are triggered … Read more

Getting the same post on my related post

‘post_not_in’ => array($post_id), Here is your problem, and there are two of them: The parameter key is misspelt There’s a massive performance hit that can be easily avoided Using the Correct Key It should be post__not_in not post_not_in. This will restore the desired behaviour, but with a huge performance hit that gets heavier as the … Read more

Create a post automatically if search result has zero results

Assuming you are using the standard WordPress search, you can get the searched number with get_search_query So this code will create a new draft post if no results were found for the search: $match = get_page_by_title( sanitize_title( get_search_query() ), OBJECT, [‘post_type’ => ‘post’] ); if ( empty( $match ) ) { wp_insert_post( [‘post_title’ => sanitize_title( … Read more

Where do I hook to have the server do something in PHP on block attribute change?

I’m not sure that I understood exactly your goal, but check if hooking to render_block does what you want, as it will modify the block’s output before it gets rendered in the frontend. Usage example: add_filter( ‘render_block’, ‘my_dynamic_data’, 10, 2 ); function my_dynamic_data( $block_content, $block ) { if(‘my_value’ === $block[‘attrs’][‘myAttribute’] ) { // Do something … Read more