</h2> <!-- List all galleries --> <div id="sthlm_galleries"> <?php /** * List all galleries */ $args = array('post_type' => 'sthlm_gallery', 'numberposts' => -1); $gallery = get_posts($args); if (!empty($gallery)) { foreach ((array) $gallery as $g) { sthlm_gallery_template($g->ID, $g->post_title); } } ?> <!-- Add gallery --> <a id="sthlm_add_gallery_button" class="sthlm-gallery-add" href="#add_sthlm_gallery_form"><?php _e('Lägg till galleri', 'sthlm_gallery'); ?> </a> <div class="clear"></div> </div>
function sthlm_gallery_ajax_add() { $title = $_POST['title']; $desc = $_POST['desc']; // check if title is set if (!empty($title)) { // Create post object $my_post = array('post_title' => $title, 'post_content' => $desc, 'post_status' => 'publish', 'post_type' => 'sthlm_gallery'); // Insert the post into the database $id = wp_insert_post($my_post); sthlm_gallery_template($id, $title); //echo '<div class="sthlm-gallery" data-id="'. $id .'" >'.$title.'</div>'; die; } }