Running WP_Query causing issue
-
Hi,
In my wordpress page, i added a form where i am getting a serial number, and this number i am matching with the custom fields and retrieving the posts. However when i click on the button, it is crashing to error page. Please check what is the issue. Somewhere it says when we put code in snippets, we have to initialize WP_Query.
function display_search_book () { return " <form method='post'> Enter book serial number: <input type='text' required name='search_book' /> <input type='submit' name='book_search' value='Add Book' /> </form> <p id='show_message'></p> "; } add_shortcode('show_num', 'display_search_book'); $message=""; if (isset($_POST['book_search'])) { $book_serial=$_POST['search_book']; $userid=get_current_user_id(); global $wpdb; $query = new WP_Query( array( 'post_type' => '3d-flip-book', 'meta_key' => 'serial_number', 'meta_value' => $book_serial ) ); if( $query->have_posts() ) { while( $query->have_posts() ) { $query->the_post(); $que=$wpdb->insert('sk_book_addition', array( 'book_id' => $post->ID, 'user_id' => $userid, ) ); if($que){$message.="Book Added !!";} else{$message.="No Book Added !!";} } } else{ $message.="No Books Found."; } } function display_messages () { return " ".$message.""; } add_shortcode('show_messages', 'display_messages');
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.