Hot answers tagged custom-post-types
3
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' => ...
2
When you initiate a Loop, split it up like so:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
<?php endwhile; ?>
<?php endif; ?>
Anything inside the if statement but outside the while statement will run if have_posts is true, but will not be ...
2
This question is borderline "not constructive", because it's going to solicit opinion rather than objective fact or expertise.
That said: my opinion is:
By default the Plugin should not touch user-generated content
It would be considerate to offer a "delete content" checkbox option at uninstall
2
This:
if (is_tag()){
will be true for any query on a tag archive page, including the query WordPress makes to load menu items.
You want to check if the current query is both the main query and tag query:
if ($query->is_main_query() && $query->is_tag()){
2
If you want to sort the custom post type 'product' by title, please try:
array( 'post_type' => 'product',
'posts_per_page' => 10,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array( 'taxonomy' => 'genre',
'field' => 'slug',
...
1
So you want to allow people to create posts from the front-end? Sure...
In this answer here I explain a very basic way in which you can achieve this very thing, front-end posts to a post type of your choice.
Here is a basic example of what you might include in your template file to do so;
(please see original answer for further details)
<?php
if ( ...
1
Rename portfolio-archive.php to front-page.php and change the post type for that page with a filter on pre_get_posts:
add_filter( 'pre_get_posts', 'wpse_99860_portfolio_on_front' );
function wpse_99860_portfolio_on_front( $query )
{
// not the main loop
if ( ! $query->is_main_query() )
return $query;
// not the front page
if ( ! ...
1
From what I gather all you need to do is query the 3 posts and step though each one using the_post(). I have not used it like this so not 100% that is how it works.
the_post() Retrieves the next post, sets up the post, sets the 'in the loop' property to true.
$project_query = array(
'posts_per_page' => 3,
'post_type' => 'projects',
...
1
You can limit your query even further...
if (
!is_admin()
&& $query->is_search()
&& ($query->get('post_type') == 'yourposttype')
) {
// ...
But if you want to query all post types but restrict those results for only one post type in the same query, you can't do that. You would need a UNION statement, probably, and WP_Query ...
Only top voted, non community-wiki answers of a minimum length are eligible