Tag Info

Hot answers tagged

13

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()) { ...


6

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


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

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' => ...


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

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

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; }


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

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.


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 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

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

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: ...


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

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

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

I've been able to solve this myself. My entire code for registering the CPT: <?php add_action( 'init', 'events_post_type_register' ); function events_post_type_register() { $post_type = "events"; $labels = array( 'name' => _x('Events', 'post type general name', 'project_X'), 'singular_name' => _x('Event', 'post type ...


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

If this is the main query, you shouldn't be creating a new query at all, just run the normal loop and you will see the posts from your CPT. The reason your custom query isn't working is that post-type is not a valid parameter, it's post_type (underscore, not hyphen). If your goal is to ultimately change the sort order of your CPT archive, then you're in ...


2

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


2

It sounds like you're very close here and your only remaining issue is that your permalinks for genres and movies collide. 'movies' CPT permalink /genres/%custom field meta box value%/%movie%/ 'genres' CPT permalink /genres/%genre%/ The issue here is using the add_permastruct. When it creates the rules for movies, they look something like this: ...


2

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( ...


2

I have expanded a bit on tungd's answer to provide more genericity with that approach. This implementation allows adding arbitrary mappings between menu 'macros' and internal Wordpress URLs that only the backend knows about. I've also decided to use ! as the prefix for these macros to avoid them clashing with named anchors - this includes an overhead to ...


2

The function get_event_list() Should looks like this … Whenever you use a custom query you must include paged variable in the query for pagination to work. Pagination Note: Use get_query_var('page'); if you want your query to work in a Page template that you've set as your static front page. The query variable 'page' also holds the pagenumber for a single ...


2

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 ( ...



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