Load scripts based on post type

If you hook onto a later action such as template_redirect, you should be able to check the query vars to determine if your specific post type is being viewed. add_action( ‘template_redirect’, ‘example_callback’ ); function example_callback() { if( is_single() && get_query_var(‘your-posttype’) ) wp_enqueue_script( .. your args .. ); } Or alternatively like this… add_action( ‘template_redirect’, ‘example_callback’ … Read more

How to: wordpress job listing and candidates details

You say that the listing is a custom post type so each job listing has a post ID so you can just pass that to your uploadcv.php in your Apply Now Button : <a href=”https://wordpress.stackexchange.com/questions/22457/.uploadcv.php?listing_id=<?php echo $post->ID; ?>”>Apply Now</a> and then retrieve that in your uploadcv.php : $listing_ID = (int)$_GET[‘listing_id’]; Now as far as saving … Read more

Include custom taxonomy term in search

I would recommend the Search Everything plugin too, but if you want to implement this using WP’s search function, here’s the code I’m using in my Atom theme: // search all taxonomies, based on: http://projects.jesseheap.com/all-projects/wordpress-plugin-tag-search-in-wordpress-23 function atom_search_where($where){ global $wpdb; if (is_search()) $where .= “OR (t.name LIKE ‘%”.get_search_query().”%’ AND {$wpdb->posts}.post_status=”publish”)”; return $where; } function atom_search_join($join){ global … Read more

How can I get this request to use the Custom Post Type page template instead?

Switch the taxonomy.php just like you would the single.php to support specific post custom templates. This is untested code, so it may not work – but, first get the post type $post_type = get_query_var(‘post_type’); So if $post_type contains post_type=”car” then include archive-car.php like this: if ( $post_type=”car” ) get_template_part(‘archive-car’); elseif ( $post_type=”boat” ) get_template_part(‘archive-boat’); elseif … Read more

don’t publish custom post type post if a meta data field isn’t valid

You can stop the post from saving all together with minor JQuery hacks and validate the fields before saving on the client side or server side with ajax: first we add our JavaScript to capture the submit/publish event and use it to submit our own ajax function before the actual submit: add_action(‘wp_print_scripts’,’my_publish_admin_hook’); function my_publish_admin_hook(){ if … Read more

Review site custom post type structure

The way that I would approach it is using the tax_query to create a query that looks for both the correct genre and type. For example, to query all Movies that are Drama: $myquery[‘tax_query’] = array( array( ‘taxonomy’ => ‘genre’, ‘terms’ => array(‘drama’), ‘field’ => ‘slug’, ), array( ‘taxonomy’ => ‘type’, ‘terms’ => array(‘movie’), ‘field’ … Read more

Custom bulk_action

I think the latest major release warrants a new answer to this question, considering the popularity of this question. Since WordPress 4.7 (released December 2016) it is possible to add custom bulk actions without using JavaScript. The filter bulk_actions-{$screen} (e.g. bulk_actions-edit-page for the pages overview) now allows you to add custom bulk actions. Furthermore, a … Read more