Returning all values from foreach in function php [closed]

Try this: function returncartdata($data) { $return = ”; foreach ($data as $carthtml => $itemhtml) { $return .= $itemhtml[0]; $return .= $itemhtml[1]; $return .= $itemhtml[2]; $return .= $itemhtml[3]; $return .= $itemhtml[4]; } return $return; } $rawhtmlcartdata = cart_items_array(); $ordercart = returncartdata($rawhtmlcartdata); wp_insert_post(array ( ‘post_type’ => ‘saved-orders’, ‘post_title’ => ‘Test’, ‘post_content’ => $ordercart, ‘post_status’ => ‘publish’, ‘comment_status’ … Read more

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