How to display regular posts & custom post types that fall under a category using just the generic category template?

Take a look at the query_posts() function – your amigo for altering the main/default query. You want to call global $wp_query beforehand to alter the original query instead of replacing it. Something like this should do the trick for you. Put the first four lines in your category.php right before the main loop begins: // … Read more

Pushing a custom post type to the top of the search results

Since WP 3.7 there is a filter “posts_search_orderby” that allow to set the ordering for search. To be sure that filter works as expected set “orderby” to “relevance”. add_action( ‘pre_get_posts’, function( $query ) { if ( $query->is_search() ) { $query->set( ‘orderby’, ‘relevance’ ); } } ); and then, assuming your profiles CPT slug is “”profiles”: … Read more

Random post, once per day

First of all you really shouldn’t be using query_posts(). Read this excellent explanation why. Then this is a perfect use case for transients. You just get the post once and then cache it for 24 hours using the Transients API. if ( false === ( $quotes = get_transient( ‘random_quote’ ) ) ) { // It … Read more

Simple way to search custom-post types only

To search for a custom post type , you can add to the query &post_type=events , to achieve this just edit your form like this <form id=”searchform” action=”http://localhost:8888/ltc” method=”get”> <input class=”inlineSearch” type=”text” name=”s” value=”Enter a keyword” onblur=”if (this.value == ”) {this.value=”Enter a keyword”;}” onfocus=”if (this.value == ‘Enter a keyword’) {this.value=””;}” /> <input type=”hidden” name=”post_type” value=”events” … Read more

Get post ID from wp_insert_post()

You’ll have to do this in two steps. First, you will create a post in the draft mode, using wp_insert_post(). The wp_insert_post itself will return to you the ID of the inserted post: <?php $new_post = array( ‘post_title’ => ‘Draft title’, ‘post_status’ => ‘draft’ ‘post_type’ => ‘my_custom_type’ ); $postId = wp_insert_post($new_post); ?> <form method=”post” action=”your-action.php”> … Read more

Query menu_order custom post types

I’ve just had to do the same thing as you, here is what I did to get this working: ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘page-attributes’) Register the post type with supports of page attributes. This adds the menu order meta box to the edit screen. From there you can place the order. Then run my … Read more

get post type plural

Edit: get_post_type_labels was never intended to be a public function. It is only used internally when registering a post type. See these trac tickets: get_taxonomy_labels() and _get_custom_object_labels() fail if $object->taxonomy is not array Fatal error: Cannot use object of type stdClass as array in /…/wp-includes/post.php on line 1202 Like you mentioned in your question you … Read more