31

After some research I found none of these answers are up to date. As of December 8, 2015 WordPress includes a new filter, register_post_type_args, which lets you hook into the arguments of a registered post type. function wp1482371_custom_post_type_args( $args, $post_type ) { if ( $post_type == "animal-species" ) { $args['rewrite'] = array( ...


19

add_action( 'admin_init', 'do_something_152677' ); function do_something_152677 () { // Global object containing current admin page global $pagenow; // If current page is post.php and post isset than query for its post type // if the post type is 'event' do something if ( 'post.php' === $pagenow && isset($_GET['post']) &&...


17

Is this function really for modifying post types Yes. and if so, can you simply redeclare a couple arguments and leave the rest alone? No. If you want to modify arguments to a post type, you need to use get_post_type_object to get the post type object, modify what you want in it, then re-register it using your modified type as the new $args parameter.


16

This is now working for me... for those of you having the same issue it turns out all the code was correct. The problem was WordPress is setup to show 10 posts per page by default which clashed with my query (limiting it to 2 posts) to fix the issue I changed the WordPress setting (Settings / Reading in the admin dashboard) to 1.


8

Here's an example of how to use the 'registered_post_type' filter to modify a post type in another plugin. A plugin I was using didn't include a menu_icon in it's definition, so I wanted to add one of my own. <?php /** * Add a menu icon to the WP-VeriteCo Timeline CPT * * The timeline plugin doesn't have a menu icon, so we hook into '...


7

I found the solution here : http://walrusinacanoe.com/web-development/742 It is elegant and functional : add_action( 'parse_query','changept' ); function changept() { if( is_category() && !is_admin() ) set_query_var( 'post_type', array( 'post', 'your_custom_type' ) ); return; }


7

The mentioned Post Types deal specifically with The Customizer. Custom CSS Post Type The custom_css post type is used to store all themes "Custom CSS" content found in The Customizer under Additional CSS. Each theme gets it's own post ( whenever the Additional CSS is saved ) with the CSS stored as post_content. Then only the active theme's post is used ...


6

@EAMann's answer is correct, but there's already a build in WordPress function for fetching all registered post types: get_post_types <?php // hook into init late, so everything is registered // you can also use get_post_types where ever. Any time after init is usually fine. add_action( 'init', 'wpse34410_init', 0, 99 ); function wpse34410_init() { ...


6

You quite likely need to simply visit your permalink settings page to refresh. Goto Admin > Settings > Permalinks. Then try your URL on the front-end again.


6

Posts If you are using WordPress as a blog, then you will end up using posts for majority of your site’s content. Posts are content entries listed in reverse chronological order on your blog’s home page. Due to their reverse chronological order, your posts are meant to be timely. Older posts are archived based on month and year. As the post gets older, the ...


5

I hope I understand the question correctly . When you move a post , the meta keys and values associated with it should remain with the post itself, like all post meta (including the attachments , custom-image etc..) - so there should be no problem to keep the values. Normally ,The only thing that SHOULD happen is a change the 'post_type' property of the ...


5

Here's my approach... First you have to select 3 latest posts, then you have to pick random one of them... But it's easier to shuffle selected posts than picking only one of them - that way you can still use normal loop: <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'post_status' => 'publish' ...


4

They don't normally show there That is how they are supposed to work. Each CPT has a feed of it's own by default Everything in WP has a feed it seems! But if you want them in your main feed this can go in your functions.php // ADDS POST TYPES TO RSS FEED function myfeed_request($qv) { if (isset($qv['feed']) && !isset($qv['post_type'])) ...


4

The first issue is that add_editor_style() is usually called in Theme setup functions that get hooked into after_setup_theme - which is well before the query is set up and the post type determined. So, you'll need to move add_editor_style() to a separate callback, that gets called after the query is setup, but before TinyMCE is initialized. Perhaps ...


4

Hook into 'registered_post_type' after the other code has registered it. It is called at the end of register_post_type(). You get two arguments: $post_type and $args. Now you can change anything for this post type. Inspect $GLOBALS['wp_post_types'] for some options.


4

I had the same issue but the answer did not work for me. In case anyone else finds this, make sure the post type title is not longer than 20 characters. That might be the issue and Wordpress will not care to let you know. Credits go to: https://stackoverflow.com/a/26029803/722036


4

If I understand well you want to show the last post (one post) from one of the 3 post types you have, using a dynamic url like http://example.com/latest. First of all lets add a filter to 'do_parse_request' filter: add_filter( 'do_parse_request', function( $bool, WP $wp ) { $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' ); $path = substr(...


4

I know you want solution "using WP_Query", but why not use get_posts() for this? $posts_ids = get_posts('post_type=post&posts_per_page=-1&fields=ids'); // $posts_ids is now an array of IDs echo implode(',', $posts_ids); // prints: 123, 124, 125, 126, ... // or foreach( $posts_ids as $id ) { echo $id; }


4

If you don't want to use a plugin, you can try implementing a meta box to be associated with that custom post type, This is the code that I use if I want to add a simple input field for a certain post type, in the example below, I assume that the member_post_type is your declared post type: function member_add_meta_box() { //this will add the metabox for ...


4

The only way this could work would be ?post_type=any based on WP_Query post_type params. But the context is the problem, the edit.php page requires a specific post type, to display and edit only one $post_type_object which returns, for each post_type, only one singular label, one plural label and so many others individual properties. These are not only ...


3

Every time you edit a post/page, WordPress creates timely revisions of it. Check the Firebug console for the requests that are sent at regular intervals when you are on the edit page. They are useful if you lose the post content at some point and want to get back to an earlier version of the post. Once you publish the final version of the post then you can ...


3

Instead of creating a string try creating an array and check. $posttypes_array = array(); foreach ($post_types as $post_type ) { $posttypes_array[] = $post_type; } And then form the query as follows $buildArgsAllQuestions = array( // Add out new query parameters 'post_type' => $posttypes_array, //'post_type' => $posttypes_array, '...


3

You need to add each individual support you need e.g. 'supports' => array('thumbnail', 'title', 'editor'), The title and editor are added by default in a post type but if you add the supports query you need to redefine them back in.


3

You could run three get_posts() calls to snag the latest post from each post type, and build the links from there. Something like this would output the most recent post from each of the three post types in an unordered list: /** * Grab the latest post from three different post types. * * @return array Array of post objects. */ function ...


3

I don't see an option for it in register_taxonomy() It's not in Codex, but is fully supported: add_action( 'init', function() { register_taxonomy( 'foo', 'post', array( 'description' => 'Hi there!' ) ); $foo = get_taxonomy( 'foo' ); echo $foo->description; // output "Hi there!" });


3

The get_post_type_object() function accepts a post type name and returns the post type object. You can then check the capability_type property of this object. Example: $post = get_post( $post_id ); $pto = get_post_type_object( $post->post_type ); $cap_type = $pto->capability_type;


3

You are missing the the_post() function call in the loop. Just add $the_query->the_post(); in your loop. Apart from that, your loop should work EDIT You should also not forget to reset your postdata after the query is done


3

As far I understood you want to set the value of $id randomly from adzones post type post ids. I hope this helps you- $args = array( 'orderby' => 'rand', 'posts_per_page' => '1', 'post_type' => 'adzones' ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $id = get_the_ID(); echo ...


2

I see a few problems with your code. you are missing post_type field in your form. the name of the taxonomy dropdown should be the name of your custom taxonomy. the form method is set to GET yet you check the selected with POST. so your form should look something like this: <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">...


2

Try this code in your template. $query = new WP_Query( array( 'post_type' => 'custom-post', 'posts_per_page' => -1 ) ); if( $query->have_posts() ){ while($query->have_posts()){ $query->the_post(); $image_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => '...


Only top voted, non community-wiki answers of a minimum length are eligible