Getting the IDs of a custom post type
Found the basis of the answer buried in the codex $args = array( ‘post_type’ => ‘case_studies’); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_ID(); endwhile;
Found the basis of the answer buried in the codex $args = array( ‘post_type’ => ‘case_studies’); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_ID(); endwhile;
I found the key: SQL CASE Expression function order_search_by_posttype($orderby){ if (!is_admin() && is_search()) : global $wpdb; $orderby = ” CASE WHEN {$wpdb->prefix}posts.post_type=”artist” THEN ‘1’ WHEN {$wpdb->prefix}posts.post_type=”post” THEN ‘2’ WHEN {$wpdb->prefix}posts.post_type=”artwork” THEN ‘3’ WHEN {$wpdb->prefix}posts.post_type=”publication” THEN ‘4’ ELSE {$wpdb->prefix}posts.post_type END ASC, {$wpdb->prefix}posts.post_title ASC”; endif; return $orderby; } add_filter(‘posts_orderby’, ‘order_search_by_posttype’);
Templates See the Template Hiearchy for a more detailed break down of how WordPress chooses the template. For a taxonomy term slug (‘monitors’ your example) in the taxonomy taxonomy (e.g. ‘products’) WordPress will try to use the following templates (in this order) taxonomy-{taxonomy}-{slug}.php taxonomy-{taxonomy}.php taxonomy.php archive.php index.php For your ‘monitors’ taxonomy term page, WordPress will … Read more
Use single-{posttype}.php for the single template. Also, if you register your post type with the has_archive argument set to true, then you can use archive-{posttype}.php for your archive template, which will allow you to skip that query that you have there, since the global $wp_query object will already be populated with your custom post type. … Read more
Ok, so I finally found what I needed here: How to get current term in my custom taxonomy in WordPress? the last update at the bottom courtesy of @user3208: <?php // Get terms for post $terms = get_the_terms( $post->ID , ‘oil’ ); // Loop over each item since it’s an array if ( $terms != … Read more
You have some messed up code. I have reformatted your code to code which actually works. The following solution allows you to give your Custom Post Type menu a menu name of what ever you want. Just change the label “menu_name”. POST TYPE // Create the news custom post type register_post_type(‘nwcm_news’, array( ‘labels’ => array( … Read more
If all of your custom post type posts have all meta fields that you need then you can use the fields argument and set it to ids which will work much faster for example: //get your custom posts ids as an array $posts = get_posts(array( ‘post_type’ => ‘your_post_type’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘fields’ … Read more
Ok – so I solved this. Here is what appears to be the problem. Comments are disabled by default for custom-post-types. This happens even if you have them enabled in the overall settings To fix it, all I had to do was the following: In SETTINGS > DISCUSSION uncheck the “Allow people to post comments … Read more
From the Codex: wp_insert_post() will fill out a default list of these but the user is required to provide the title and content otherwise the database write will fail. $id = wp_insert_post(array( ‘post_title’=>’random’, ‘post_type’=>’custom_post’, ‘post_content’=>’demo text’ ));
There are two types of 404 errors: WordPress-generated, and server-generated. In some server environments, 404s could be inaccurately displayed by the server in cases of CPU overload or due to certain instances of misconfiguration, etc. Usually server-generated 404 errors will say something like “Nginx” or “Apache” at the bottom of the page (depends on server … Read more