Adding custom theme template to custom post type [duplicate]

File should be single-member_post.php instead of single-memberPost.php. In single-{posttype} , {post_type} is the $post_type argument of the register_post_type() function. Never use flush_rewrite_rules(); in init use it only on theme/plugin deactivate or activate. Since this is a theme you can use it on after_switch_theme hook. add_action( ‘init’, ‘my_cpt_init’ ); function register_cpt_member_post() { register_post_type( … ); } … Read more

ACF select box css color change

You will need to store the field value in a variable and use the get_field() instead of the_field() function. From there you can introduce your own custom control structure to set the color you want. Here is a snippet <?php //store the value in a variable first $option = get_field(“status”); if($option==”K dispozicii”){ ?> <p style=”color:green”>$option</p> … Read more

Why WordPress does not Use Separate Table for Post Types (When Registring)?

It would be a challenge to hunt down a specific moment in time when that particular decision had been made. My educated guess would be that storing CPT definitions persistently would complicate how they interact with rest of APIs (especially Rewrite and localization). WP is also relatively conservative with database structure. CPT are relatively young … Read more

WordPress Roles

Create function to give role a numeric value: function get_user_level($role){ switch ($role) { case ‘Contributor’: return 1; ); break; case ‘Author’: return 2; ); break; case ‘Editor’: return 4; break; case ‘Administrator’: return 5; break; case ‘Super Admin’: return 6; break; default: return 0; // default subscriber or other roles break; } } Now you … Read more

How to set up a echo? [closed]

You can use get_post_type() function and pass current post id to it. global $post; if(get_post_type($post->ID) == ‘videos’) { // do this } Update <?php global $post; if(get_post_type($post->ID) == ‘videos’) { ?> <video class=”video” width=”https://wordpress.stackexchange.com/questions/91208/<?php echo get_field(“width’); ?>” height=”https://wordpress.stackexchange.com/questions/91208/<?php echo get_field(“height’); ?>” controls preload> <source src=”https://wordpress.stackexchange.com/questions/91208/<?php echo get_field(“mp4′); ?>” media=”only screen and (min-device-width: 960px)”></source> <source src=”https://wordpress.stackexchange.com/questions/91208/<?php … Read more

Good practical way to do loop within loop to show child custom type using a template code

<?php global $post; foreach ($event_photos_obj as $post) : … … // set up product in order to use native wordpress api setup_postdata($post); /* Include the single view for the product (photo). */ include ….. endforeach; wp_reset_postdata();?> my mistake my code is that setup_postdata with $product instead of $post as the tutorial said : https://codex.wordpress.org/Function_Reference/setup_postdata This … Read more

Custom Field Search

Use pre_get_posts to filter search results: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set(‘post_type’, ‘custom_post_type_name’); $query->set(‘cat’, intval($_POST[‘cat’]); // assuming you have a select with categories with name “cat” } } } add_action(‘pre_get_posts’,’search_filter’);