Skip to main content
Share Your Experience: Take the 2024 Developer Survey
12 votes
Accepted

Loading custom page template via plugin

To add custom template in page attributes template section you have to first add your template to dropdown and load it in template_include hook when current page has selected it as current template. /...
kierzniak's user avatar
  • 2,432
10 votes

How to get the custom post type from an archive page?

Here is the function you want: /** * Get the current archive post type name (e.g: post, page, product). * * @return String|Boolean The archive post type name or false if not in an archive page. *...
Nabil Kadimi's user avatar
  • 2,686
9 votes
Accepted

Add custom field to the archive page?

Using the Advanced Custom Fields plugin you can assign options pages to you custom posttype like this: if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( '...
Luckyfella's user avatar
6 votes
Accepted

Change number of posts to show on Archive page (custom post type)

Just make sure you're not in the admin when changing the query: function num_posts_archive_project_ie($query) { if (!is_admin() && $query->is_archive('projects-ie') && $query-&...
janh's user avatar
  • 2,738
5 votes

Custom Post Type Archive template page not found

I don't think you need to use the hook pre_get_posts on this. Remove that part from functions.php. Then just put the archive-technology.php in themes root directory. Then go to you Permalinks settings ...
CodeMascot's user avatar
  • 4,527
5 votes

How to get the custom post type from an archive page?

I see this in a few comments on the accepted answer, but wanted to make this point clear for others skimming over these answers: The global $wp_query object is more reliable for getting the archive's ...
James's user avatar
  • 208
4 votes
Accepted

Custom Post Archive is not working

why don't you try adding: 'has_archive' => true, to your code? so replace this line: 'public' => true, with this: 'public' => true, 'has_archive' ...
rudtek's user avatar
  • 6,121
4 votes

creating custom archive template within plugin for custom post type using archive_template filter

I was able to get it working as desired using the condition is_archive() && get_post_type($post) == 'product'. I also created a custom taxonomy for products as product-category below is the ...
toddash's user avatar
  • 61
4 votes
Accepted

Rewrite URL for only archive page (custom post type)

You can have a separate slug for the post type archive by setting the slug as the value for the has_archive argument, instead of just true: register_post_type( 'event', array( '...
Jacob Peattie's user avatar
3 votes
Accepted

Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy

WP defaults to showing normal native Posts in archives. It won't automagically pick up which post types you want in your archive. You will have to adjust main query for it to explain that to it, with ...
Rarst's user avatar
  • 99.6k
3 votes
Accepted

get_terms in a taxonomy template

get_terms returns array of terms and not only one term, so you can't do $terms->slug, because it makes no sense at all... If you want to display all terms, you'll have to loop through them: $...
Krzysiek Dróżdż's user avatar
3 votes
Accepted

Wordpress override archive page template using a plugin

You should create a filter to the archive_template template hook. function use_custom_template($tpl){ if ( is_post_type_archive ( 'books' ) ) { $tpl = plugin_dir_path( __FILE__ ) . '/tpl/dir/...
hamdirizal's user avatar
2 votes
Accepted

How To Create A Paginated List Of All Categories On My Site?

Paging a list of terms/categories/tags are quite easy, and to achieve that, you need minimal info. Lets look at we need the amount of terms the amount of terms per page get_terms() (Just note, the ...
Pieter Goosen's user avatar
2 votes

Increase 10 post limit per page

It seems your theme (or one of your plugins) has reduced the query to 10 posts per page.Otherwise, changing the option in the Settings page has to change the number of posts per page. Check code of ...
Hadi77's user avatar
  • 31
2 votes
Accepted

Which php file lists all the post of a category

WordPress uses a hierarchy of templates (see the visual overview) which it checks for presence. In your case when showing a category archive it will check for presence the following files in this ...
JHoffmann's user avatar
  • 1,850
2 votes

How to get the custom post type from an archive page?

die(var_dump(get_taxonomy(get_queried_object()->taxonomy)->object_type)); I thinks that is the answer for your question. Happy coding!!!
Vũ Trọng Quang's user avatar
2 votes
Accepted

Custom Taxonomy Archive BUG

as mentioned by @mmm you loop over the terms and in each term you loop over each project – however I think this is what you wanted to do: $terms = get_terms( array( 'taxonomy' => '...
s t's user avatar
  • 176
2 votes
Accepted

Not able to see CPT archive template

I set my system up with the exact same as your code above. I get the same results. What I did to fix it was change your line 'rewrite' => array( 'slug' => 'articles', 'with_front' => ...
rudtek's user avatar
  • 6,121
2 votes

Display custom post types in wp_list_pages

To simplify things, first make your archives actual Archives - not Pages. That will help you later on in listing the correct content. unregister_post_type('blog'); unregister_post_type('event'); ...
WebElaine's user avatar
  • 9,430
2 votes
Accepted

How To Create A Custom Taxonomy 404 Page

You can filter any type of template to override the template hierarchy. In this case the filter is 404_template. We'll check if the location query var is set, meaning the URL matched the pattern of a ...
Milo's user avatar
  • 78.5k
2 votes

Wordpress subcategories return 404 in custom template

I have seen the magic "." break a lot of sites paginations and do errors to such issues as yours (return status 404 for subcategories). Try installing a plugin named "WP No category base" (link below) ...
Haris's user avatar
  • 151
2 votes
Accepted

archive_template override when no posts exist

One way to accomplish this may be to use the pre_get_posts to conditionally add the single_template and archive_template filters. namespace StackExchange\WordPress; /** * Add filters for `...
Nathan Johnson's user avatar
2 votes
Accepted

IF taxonomy archive is hierarchical THEN

Look at the docs (please read the docs) for is_taxonomy_hierarchical(). You need to tell it which taxonomy you're checking: if ( is_taxonomy_hierarchical( 'my_taxonomy_name' ) ) { } If you're ...
Jacob Peattie's user avatar
2 votes
Accepted

How to list articles by year based on url?

Avoid using query_posts() Please don't use query_posts('posts_per_page=10'); in your date.php template file as it will override the main query instance and thus affect the main loop. This can ...
birgire's user avatar
  • 67.4k
2 votes
Accepted

How to make posts under custom post type not generate a URL / post

Looking at the class and function you're using, this method is a little problematic: public function buildPostArgs( $slug, $singular = 'Post', $plural = 'Posts', $args = array() ) { $args = ...
Tom J Nowell's user avatar
  • 59.4k
2 votes
Accepted

post loop with different design depending on post

Your $count++ needs to be after your endif statement. It's not counting up because your counter is always at 0 which means you're always in your "if" portion of your statement not your &...
rudtek's user avatar
  • 6,121
1 vote

Which Template Page Should I Use?

I'm struggling to figure out how to filter the FAQs to show for a specific audience. My archive-faqs.php lists all FAQs regardless of audience type. So you have FAQs You have some FAQs appropriate ...
Tom J Nowell's user avatar
  • 59.4k
1 vote
Accepted

Which Template Page Should I Use?

you could always make a custom wp_query and put it in a template-custom.php. $the_query = new WP_Query( array( 'post_type' => 'faqs', 'tax_query' => array( array ( '...
rudtek's user avatar
  • 6,121
1 vote

Custom template for archive of a custom taxonomy

I think the best way to do it is to create a custom template page and get the list of terms (or whatever you need) on that template. template-activities-taxonomy.php <?php /* Template Name: ...
dbeja's user avatar
  • 1,069
1 vote

show ALL latest posts with archive.php on example.com/latest

I don't think you need a rewrite rule at all. You can simply alter the main query when you're on archive.php, like so: add_action( 'pre_get_posts', 'show_all_posts' ); function show_all_posts( $...
grazdev's user avatar
  • 1,323

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