Automatically assign a custom post to a custom taxonomy based on custom field value

I’m sure this not best answer, however you may try like this add_action(‘save_post’, ‘add_my_taxonomy’); function add_my_taxonomy($post_ID) { $area = array( ‘ny’ => ‘New York’, ‘la’ => ‘Los Angeles’ ); $zip = array( ‘ny’ => ‘10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10011, 10012, 10013, 10014, 10015, 10016, 10017, 10018, 10019, 10020, 10021, … Read more

WP_Query on custom post type not displaying, multiple loops & get_template_part

I think you forgot to check if $the_query have posts. <?php $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’ ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class=”testimonial push_2 grid_10 clearfix”> <blockquote>&ldquo;<?php the_field( ‘testimonial’ ); ?>&rdquo;</blockquote> <cite>&mdash;<?php … Read more

How to remove CPT comment feed from head?

Following command hides comments feed for posts (WP 4.4+ required!), but custom pages still have comments feed displayed, even if comments are disabled for such page: add_filter( ‘feed_links_show_comments_feed’, ‘__return_false’ ); To resolve this, I had to add this addidtional code too: function remove_comments_rss( $for_comments ) { return; } add_filter(‘post_comments_feed_link’,’remove_comments_rss’);

How to properly prefix blog post URL’s

Assuming that you are not using a plugin to handle your post types but are registering them manually: Add the rewrite argument to your register_post_type() function calls. $rewrite = array( ‘slug’ => $slug, ‘with_front’ => false ); $args = array( // your other arguments ‘rewrite’ => $rewrite ); register_post_type( ‘name_of_your_post_type’, $args ); If your registering … Read more

Maintaining WP_Query Relation Among CPT, Custom Taxonomy, Permalinks- CPT UI

Collaborative efforts- For http://novice.dev/books just create custom post type and check rewrite options so that it adds end points. For http://novice.dev/books/book_categories/my_story_books, create custom taxonomy related with the post type and check the options for rewrite options. http://novice.dev/books/thirty-days-and-night will be automatically when above two are done.

Change 2 fields in the post depending on the 3rd field before save

Use the hook save_post and put an if inside the function that do the save after the ‘normal’ save meta fields routine. add_action( ‘save_post’, ‘this_is_the_function_name’ ); function this_is_the_function_name( $post_id ) { // No auto saves if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; // make sure the current user can edit the post if( ! … Read more

How to show a tag archive of one post type only

I’ve worked out a solution to this. I hope this can help someone else. First add the following two functions to your functions.php (or plugin) file: function get_terms_by_post_type( $taxonomies, $post_types ) { global $wpdb; $query = $wpdb->prepare( “SELECT t.*, COUNT(*) from $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN … Read more

Use Custom Database with Custom Post Type

What I understand is you want to update records/table to another database from wordpress…. well you can achieve this in wordpress 3.1> using $newwpdb = new wpdb(“mysqluser”,”mysqlpassword”,”mysqldbname”,”mysqlhost”); Then using $newwpdb you can access table from new database and perform all operation on it like edit/delete update/insert… same as $wpdb do wordpress…. Hope that helps or … Read more