Can one create multiple Custom Post Types with a for loop?

You have a problem with scopes in your code and you misuse actions, I guess. Let me explain… Let’s take a look at this part of code: for($i =1; $i <= $options_foo[‘num_post_types’]; $i++) { global $options_foo; $singular = $options_foo[‘post_type_names’][$i][‘singular’]; $plural = $options_foo[‘post_type_names’][$i][‘plural’]; add_action(‘init’, function(){ global $singular; What it does, is: You loop through all options … Read more

Using taxonomy term in CPT permalink – Pages 404’s

Ended up with commenting out line 4 and changing the filter into this: add_filter(‘post_type_link’, function ( $post_link, $post, $id = 0 ) { if ( ‘project’ != $post->post_type || ‘publish’ != $post->post_status ) { return $post_link; } $post = get_post($id); if (is_object( $post ) && $post->post_type == ‘project’ ) { $terms = wp_get_object_terms( $post->ID, ‘department’ … Read more

Custom template Page 2 not working

Please modify your query as: $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $posts_per_page = get_option( ‘posts_per_page’ ); $artPosts= new WP_Query( array( ‘post_type’ => ‘art’, ‘posts_per_page’ => $posts_per_page, ‘post_status’ => ‘publish’, ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ‘paged’ => $paged )); <?php if ( $artPosts->have_posts() ) : ?> <?php while … Read more

Broken featured images are uploading from frontend

This is the answer of my own question it’ll definitely help others to solve same problem. <?php add_action( ‘wp_ajax_bpem_event_form_response’, ‘bpem_event_form_response’ ); add_action( ‘wp_ajax_nopriv_bpem_event_form_response’, ‘bpem_event_form_response’ ); function bpem_event_form_response() { $title = sanitize_text_field($_POST[‘ev_title’]); $content = $_POST[‘ev_desc’]; $image_url = sanitize_text_field($_POST[‘ev_image’]); $location = sanitize_text_field($_POST[‘ev_location’]); $start_date = sanitize_text_field($_POST[‘ev_start_date’]); $start_time = sanitize_text_field($_POST[‘ev_start_time’]); $end_date = sanitize_text_field($_POST[‘ev_end_date’]); $end_time = sanitize_text_field($_POST[‘ev_end_time’]); $ev_organizer = sanitize_text_field($_POST[‘ev_organizer’]); … Read more