WP_Query with AJAX returning empty array

$response->status, $response->query etc. is not how you set array values in PHP. So you’re just returning that empty array you defined at the beginning. To set a value on an array use square brackets and string for the key: $response[‘status’] = true; Do that everywhere you currently have ->. Also, if you can get the … Read more

The session works on the local server, but not on the web server

Are you doing this in a plugin or on a template file? Also, you certainly want to ensure that you’re properly setting up sessions. I recommend doing so in functions.php. e.g: add_action(‘init’, ‘track_sessions’, 1); function track_sessions() { // if session isn’t active, set it if(!session_id()) { session_start(); } } And using them as you are: … Read more

Wpdb get->results to out the the month from the db

You could use the MONTHNAME(dato) on your select Like $rows = $wpdb->get_results( “SELECT MONTHNAME(dato) as month_name, avg(fiske_vaegt) as fiske_vaegt FROM `wp_registreringer` WHERE MONTH(dato) = 11 AND YEAR(dato) = 2017;”); and access it like this echo $row->month_name

Send notification email to admin for every new post published

You can use the transition_post_status hook. <?php add_action( ‘transition_post_status’, ‘custom_send_admin_email’, 10, 3 ); function custom_send_admin_email( $new_status, $old_status, $post ) { if ( ‘publish’ === $new_status && ‘publish’ !== $old_status ) { // Consider sending an email here. } } Here’s a second example that also checks for a specific post type. Note that $post is … Read more

Fatal error: Cannot redeclare function

This is the example code to fix the fatal error and redirect user as per the given page id. You can further optimise the code, if the redirection is going to remain same for “DE” and “US” for all the pages, you can just skip the if ( is_page( 90 ) ) check for these … Read more