Tag Info

Hot answers tagged

20

After you have set a static page as your home page you can add this to your functions.php and you are good to go. This will call the archive-POSTTYPE.php template correctly as well. add_action("pre_get_posts", "custom_front_page"); function custom_front_page($wp_query){ //Ensure this filter isn't applied to the admin area if(is_admin()) { ...


8

The has_archive parameter for register_post_type() does exactly what you expect it to do. However, it modifies rewrite rules when set. So, if you change it to false, you'll need to flush your rewrite rules in order for the archive index display to be removed entirely.


7

try 'has_archive' => 'true'; and do the permalink reset before testing! and it should be singular archive-job.php rather than archives-job.php


7

Given the standard registration, you should have the following: A post type with the name 'recipe' A recipe post archive at example.com/recipe/ Recipe posts with urls that take the form example.com/recipe/helloworldrecipe/ A template archive-recipe.php A template single-recipe.php However, I see this in your registration code: 'rewrite' => ...


6

I know this is old but I have this problem too and I found a rather clean way to handle it is to use a custom menu walker class KB_Custom_Menu_Walker extends Walker_Nav_Menu { protected static $custom_post_types = array(); public function start_el(&$output, $item, $depth=0, $args=array(), $id=0) { if (isset( self::$custom_post_types[ ...


5

To get the current post type use get_post_type(). Then ask get_post_type_object() for all the data you need, for example the slug: $post_type = get_post_type(); if ( $post_type ) { $post_type_data = get_post_type_object( $post_type ); $post_type_slug = $post_type_data->rewrite['slug']; echo $post_type_slug; }


5

That's because 'meta_key' and 'meta_value' are not public query vars. In other words, you can't use them in URLs directly, nor should you. Instead, register a specific query var, like so: function register_my_qv() { global $wp; $wp->add_query_var( 'my_qv' ); } add_action( 'init', 'register_my_qv' ); Then, you can go to a URL like this: ...


5

your best opption is custom link with full url as Custom post types archives are different form taxonomy based archives (categories,tags,any custom taxonomy) and date based archives which have there own archive slug.


4

Hook into '404_template'. (Example) Fetch all public custom post types where has_archive is not FALSE. Find the post type’s has_archive string and see if it is part of the current request’s url. Try get_page_by_title() with the last part of the requests. wp_redirect() to the found post’s permalink. exit;.


4

Include your template files in your plugin. I stick mine in /plugin/templates. You need to hook into template location for that template: add_filter('archive_template', 'yourplugin_get_custom_archive_template'); function yourplugin_get_custom_archive_template($template) { global $wp_query; if (is_post_type_archive('yourCPT')) { ...


4

You can use the archive_template hook to process the content of a theme's archive template, by using the scheme below, but obviously you'll only ever be able to process a fraction of the themes out there, given that a template can basically contain any old thing. The scheme is to load the template into a string ($tpl_str) in the archive_template filter, ...


3

Updated approach The first thought/suggestion I made actually - like you said - doesn't work as I understood it. At least I tried it and couldn't figure it out. That said, what you want is still achievable, but not by using a endpoint or at least not by making use of add_rewrite_endpoint(). However I figured it should be possible via a "ordinary" rewrite ...


3

Get all custom post types: $post_types = get_post_types( array ( '_builtin' => FALSE ), 'objects' ); Sort them by their name: uasort( $post_types, 'sort_cpts_by_label' ); /** * Sort post types by their display label. * * @param object $cpt1 * @param object $cpt2 * @return int */ function sort_cpts_by_label( $cpt1, $cpt2 ) { return ...


3

as determined in the comments, the page URI is ?post_type=photos&genre=boudoir... The reason why "archive-{$post_type}.php" isn't used in this case is because the page is a taxonomy archive and not a custom post type archive. WordPress is looking for taxonomy-genre.php instead of archive-photos.php, and not finding it, is defaulting back to good old ...


3

This should work for you: // grab all public post types $post_types = get_post_types( array('public' => true), 'names' ); // loops through each post type foreach( $post_types as $type ) { // setup the query $query_args = array( 'post_type' => $type, 'posts_per_page' => 1 ); // perform the query $items = ...


3

Why don't you try using a home.php file and place your desired loop/query within that file or alternatively use get_template_part to retrieve a file that contains your loop. Can you please show us your code? What I frequently do is structure my index.php like so, <?php get_header(); ?> <?php if ( is_home() ) { ...


3

You can pass a string for has_archive. That string will be used as archive URL. So in your registration code use: 'has_archive' => 'jobs' From the register_post_type() declaration in WordPress core: if ( $args->has_archive ) { $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive; if ( ...


3

Here's an example using add_rewrite_rule to handle years and months for a custom post type where news is the slug. Visit the Settings > Permalinks page in admin to flush rewrite rules after this is added. You could also put this in a plugin and flush rewrite rules on plugin activation. function wpa83797_news_rewrite_rules(){ add_rewrite_rule( ...


3

You can use getarchives_where hook of wp_get_archives() function Add this function to your functions.php: function Cpt_getarchives_where_filter( $where , $r ) { $post_type = 'blog'; return str_replace( "post_type = 'post'" , "post_type = '$post_type'" , $where ); } Then when you want your monthly archive put this: add_filter( 'getarchives_where' , ...


3

Replace your code with the following. I have made some changes to the post_type_link filter's callback function. function my_custom_post_work() { $labels = array( 'name' => _x( 'Work', 'post type general name' ), 'singular_name' => _x( 'Work', 'post type singular name' ), 'add_new' => _x( ...


3

If you'd like to list the individual courses, i.e. the taxonomy terms, you'd use neither WP_Query nor the WP standard Loop. Instead, make use of the get_terms function to retrieve the courses. It returns an array of term objects (if the taxonomy does exist and has terms matching the function arguments). Iterate over that and do something with it, such as ...


3

How did you create the link with your category '39'? Is it a custom taxonomy? Here's the test i just did and it works fine: In functions.php i created the custom post type 'recipe': add_action( 'init', 'create_recipe' ); function create_recipe() { register_post_type( 'recipe', array( 'labels' => array( 'name' ...


3

This conflict normally happens when a custom post type archive and a normal wordpress page has the same slug. The custom post type archive has the higher priority here. If you have a custom post type by the name 'Projects' and 'has_archive' is set to true for the custom post type then the conflict will arise. Set 'has_archive' to false so that it shows the ...


3

Try this piece of code for page template. I've used it on one of my projects. It outputs taxonomy term one by one with list of all posts with this term. (Just replace YOUR_TAXONOMY_SLUG to yours) <div id="content"> <h2 class="entry-title"><?php the_title(); ?></h2> <div id="post-<?php the_ID(); ?>" <?php post_class(); ...


3

I did something similar for a client a while back, I'll give you some of the code here as-is that you can possibly adapt to your needs. I'll warn you, it's quite a bit to parse through! First, I set up some custom rewrite rules to get the year/month URL structure and some query vars to pass the year and month to my template. In this example I have a page ...


2

When using custom post types I got around this problem by using the following code. Of course you will need to put in the HTML for how you want it to display on your site. <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(''); // Enter you query here ?> <?php while ...


2

It's still early for me, but you need to check for if( $events_query->have_posts() ) : rather than if( have_posts ) : as the latter will be checking against the current post type and not your custom query.


2

you can query_posts and orderby=title: <?php //*The Query*// $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; query_posts($query_string . '&post_type=YOUR-POST-TYPE&posts_per_page=1&orderby=title&order=asc&paged='.$paged); if(have_posts()) : while(have_posts()) : the_post(); ?> <?php endwhile; ?> ...


2

replace: return str_replace( "post_type = 'post'" , "post_type IN ( $post_types )" , $where ); with: return str_replace( "post_type = 'post'" , "post_type = 'YOUR_CUSTOM_TYPE'" , $where ); and change YOUR_CUSTOM_TYPE to your actual custom post type name. Update: If you want all types but pages then change your function abit to this: add_filter( ...


2

An FYI for those coming back to this question, this was fixed in 3.2: http://core.trac.wordpress.org/ticket/17316



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