WordPress Custom Post Type Issue - wordpress

my situation is I registered a custom post type named 'products' and I included 'has_archive' => true in the parameter to enable an archive template for this custom post type, I also created a archive-products.php as the template for displaying post per taxonomy of 'products', but what I noticed is when I enabled 'has_archive' => true what happens is archive-products.php acts as the index page template of the 'products' custom post type instead of the 'page-products.php' file that I created as the index page template for listing all the post of 'products' custom post type.
then when I click a link to the product-category this archive-products.php uses the default archive.php as it's archive page template. it really acts weird and now I don't know what to do next.
what I want to happen is prevent this from happening and let page-products.php act as the default index page template for listing the posts (as it should be) and for archive-products.php to be used by page-products.php as it should be doing.
thanks I hope someone can help me into this issue.
by the way I'm using WordPress 3.5.1

I faced the same problem in the last days, and take a couple of hours to search for a solution, in my case the solution was to add this following functions to you functions.php file: flush_rewrite_rules(false);
I hope it can help you :)

you can check this plugin for your custom post display
wordpress.org/plugins/wp-custom-post-field
on here create your custom post and use shortcode for display post.

Related

Parent permalink slug before CPT slug

I'm currently busy making a FAQ for my website but i'm struggling with the permalink structure.
I have made a regular page where people can see an overview of the FAQs. I called that page Klantadvies.
I installed a Custom Post Type plugin and made a post type called faq. I also made a taxonomy which is called onderwerp.
Unfortunately the plugin won't allow me to have a page parent in the slug. So i'm wondering if it's possible to have my page slug (klantadvies) in front of the custom post type slug. For example:
http://mypage.com/klantadvies/faq/onderwerp
Thnx in advance!
Rather than using a plugin for your post types and taxonomies, I'd recommend you use these two solutions:
https://generatewp.com/post-type/
https://generatewp.com/taxonomy/
You can use those to create your Post Type and Taxonomies. Within each of those configs you're allowed to setup the slugs / URL structure that you want to use.
On top of that you're going to need to setup a custom rewrite rule to handle echoing out the values you're looking for on the appropriate layout.
https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

How to enable builtin permalink edit for custom post type?

When editing/creating a post or page the permalink is shown directly under the title field and you can edit it.
Is there a way to activate the same function for a custom post type?
You should be able to do that by default. This is how I add my custom post type:
register_post_type("oproep", array("labels" => array("name" => "Oproep", 'singular_name' => "Oproep"),
'public' => true, 'has_archive' => true));
When I create a new post of type oproep, the slug is changeable as soon as i gave my post a title. Also I can change if I edit it later like any other post.
The Permalink Editor depends on the publicly_queryable attribute of register_post_type and as well on the rewrite attribute.
This is by default true in both, which is why #berend solution above works.
It won't appear if you set those attributes to false
Which is a classic weirdo behaviour of WordPress, to mix things that have zero relation to each other.
However that is as it is.
If you want the Permalink to show in the Edit Post Screen, you must set publicly_queryable to true.
That will not yet allow you to edit it.
To edit it, you must also set the rewrite to true.
If you want the register_post_type to set the Post type to non publicly queryable/unrewritable and still want to edit the "permalink" you can add use/add the Slug edit metabox instead.
It is exactly the same, just that it is in a metkbox instead of the permalink edit area.
The rewrite and publicly_queryable have nothing to do whatsoever with what we are able to edit in that "Permalink" editor, but since WP uses the rewrite to show a pretty link there, it is depending on it.
As said, it is basically the same as the slug editor, except what shows in it.
Hierarchical Post Types, where the slug stays the slug of the single post, but the "Permalink" will be site.com/parent/child, will show that url in the permalink editor, not in the slug editor.
child in this case is the slug of the post. parent is the slug of the parent.
Again, you can only edit the slug in both editors, but for cumbersome reasons WP thinks to know better and does not allow to edit the permalink if you do not set those attributes to true.

Write the content page 'Home' on the code or let the user customize it?

Let's say I have to code the page 'Home' of this site, what should I do as a programmer? Write the content in the template and if the user needs a modification make him call me or show the content by reading a specific posts of a determined category?
For example, create a category 'slideshow' and loop through it and add as many slides as posts are or a category 'why love us' and do the same?
How senior programmers in WordPress face this?
You have create one template as you say that will be home, Now if i am a developer for this site , i will divide this i.e.
Slider => May use plugin or custom post type.
Why Love Us => May be a custom filed is this is fixed in size, or may create custom post type
Our Teachers => Will be a custom post type.
Courses => Another custom post type
Testimonial => Another Custom post type
Gallery => It is easy to use plugin or wordpress built in media gallary
Blog => Will be popular or recent post
Other general things will be a theme options
So, you can manage your back-end like this so use can easily understood and easy to modify or update content.

wp get post if a custom field has value

am using WCK plugin for Custom Post Types and Fields
Its seems nice and i have done my work fine
One of my Custom Types has a custom field for upload an mp3 file
And now i want to get all the custom posts that have value for this mp3 field.
In other situations for example get all post that have thumbnail i use
'meta_key' => '_thumbnail_id'
Is there any similar approach to get the custom posts that have the mp3 field set.
UPDATE
Searching the db i noticed that there is a child post as attachment, so maybe its not a custom field problem and maybe i need to get the post that actually have attachment
Thanks
try use 'meta_key' => 'name_your_custom_field_for_mp3' You can see ACF documentation about this

Post Types, Taxonomies and routing

I'm ready to give up on Wordpress.
I've got this issue. I have created a custom post-type via wp-types plugin. I can display it and display posts from it.
However, I have created a custom page with a custom template that renders the posts. I have done so because the site uses multiple languages, and I needed the url to be in that specific language.
Thus the post-type is not displayed through the standard archive-{post-type-name}.php file, but instead a custom template and a custom wordpress page.
Just because I need the urls to be in the same language as the given page language, example:
myurl.com/{name_in_one_language}
and
myurl.com/{name_in_another_language}
The issue with that is that my custom post-type has custom taxonomies attached to it. Before the posts are rendered I select the taxonomy and then render the rest of the page based on the taxonomy name. Example:
myurl.com/paintings/?category=category_name
|| or ||
myurl.com/paintings/?author=painting_author
The thing is that the client doesn't like that kind of custom url parameters. He is begging for me to change it to the following format:
myurl.com/paintings/{taxonomy}/{painting}
Where taxonomy is either authors name or art type. And the paintings page itself is just a middleware to select which post with the needed taxonomy needs to be displayed.
I have ran out of ideas of how to do it. Completely.
I tried going with the archive-{post-type-name}.php solution, have no clue how wp-types plugin rewrite works. Tried using the wordpress permalink syntax in the plugin, doesn't recognize it.
Basically what I need is the following: For my custom page that has a custom template that renders custom post-type with custom taxonomies to route in the following way:
myurl.com/{page-with-template-that-renders-custom-post-type}/{post-type-taxonomy}/{post}
I really find Wordpress difficult to work with, the way you have to inject code, handle routes, register types. It feels like you're just patching it together to make a horrible monster that spews code bile over everyone.
First, set your permalink settings to 'Post name'. Read through Wordpress' template hierarchy to understand how things work: https://codex.wordpress.org/Template_Hierarchy
If you create a taxonomy-{taxonomy-slug}.php template, you can then navigate to myurl.com/paintings/{taxonomy}/{taxonomy-term} and use the following within your template
$taxonomy = get_query_var( 'taxonomy' );
$term = get_query_var( 'term' );
.. and use those variables in your query.
A single-{post-type-slug}.php would be used to render the post itself.
I would argue that it is not advisable to include the taxonomy in the URL of the post as these could change, or you could have multiple terms associated with a post. But, if it's necessary, check out this article: http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks

Resources