Thanks so much for these tutorials - I really appreciate how detailed you are in your explanations, and how you slowly explain WHY you're doing things as you go. Super helpful!
Thank you so much for your positive comment. Sometimes I think maybe I'm going to slow and my explanations are boring. I'm glad you find them useful. Happy Coding
I also had issues with the portfolio page showing the 404 page. I solved the problem by setting the Permalink structure to Post Name inside of the Permalink Settings (WordPress Admin Panel -> Settings>Permalinks). - Update Just noticed you mentioned it later in the course.
Hi, Alessandro! I want to say THANK YOU! You make really awesome videos. Moreover you have a talent for explaining. I really appreciate you and your work!
Hey Alex, if you want to add a link to the archive page all you need to do is go to Appearances -> Menus -> Portfolio and then click on View All, there you will find a checkbox that allows you to select the archive page for it in a dynamic way
+Alessandro Castellani yeah I found it because I couldn't get the custom archive page to work, Turns out I didn't have a content-archive.php page, I added that and it all worked like a charm, I did not follow this from the beginning so probably you mentioned it in another video but not in this one so I was lost for a couple of hours there... So if I wanted to I don't need to create a page template but I can simply edit the archive-portfolio.php page directly right?
+Alessandro Castellani one more question, did you make a video about hierarchical custom post types? Could you make one? if you did could you link it in the reply? Thanks!!!!
Is there a way to limit the length of a custom post type (meaning allowing the post to be let say 250 characters long- not using the excerpt but limiting the actual post length)?
thank you so much for this tutorial it is very helpful. may i ask for some question? how to display all the list of categories in the specific post type.
Hi, Alessandro. I enjoy your videos very much - have some trouble with development environment being different to yours, but getting latest file(s) from GitHub helps. FYI - you are on a Mac using Safari, and am on Windows using Firefox, This video (WP101 Part 19), suggests creating 'Work' as a template to make it dynamic when one has multiple custom post types. I didn't catch this 'dynamic' bit as you still coded 'Portfolio' itno array('psot_type', ..). Incidentally, as the videos age i.e. you talked about Walker class when WordPress was version 2.x but is now 5.x. Is the Walker class really relevant any more? Cheers, Chun
Hi Alessandro, first of all, thank you for making these wordpress tutorials, I've learnt a lot with your videos! I have a question concerning wordpress theme. I want to create a one-page website with different layers (works, contact, gallery, ...) and I'd like to know from your point of view what kind of structure should I start with? I was thinking about using posts or pages that will be displayed in the front-page but I'm not sure if I'm in the right path...
I'd use pages for the different sections, in this way you can call everything with custom WP_Query directly in the index.php and build everything in one single page.
Hi Alex,thank you for your tuturials. They are amazing, as always. Would like to ask you, did you end up making the live dev session to style to pages as you said in the end of this tutorial? I can't find it in your channel. thank you.
+Jozef Sedlak Hi Jozef, thank you so much for following. Unfortunately I wasn't able to do the Live Session due to connectivity problems. Sorry about that
+Alessandro Castellani , Thank you for these perfect lessons! I learned a lot thanks to you! I have a question: If i want to add a widget with list of posts or archive from Portfolio (custom post type), what will I need to do? Thank you!
+Aleksandr Nadtochyi Hi, thank you so much for following. The easy solution is to use a plugin, otherwise you have to code a widget from scratch. I've already planned that series, I will do that as soon as the current series it's finished. Happy Coding!
Hey Alessandro, do you know any reason why the the 'post_per_page' argument would NOT be working. I havent gotten this to work at all. Whatever number is in the 'Blog pages show at most' Reading Settings in the Admin is the number blog posts that get shown. Any idea how to correct this?
hello Alessandro i have changed my permalink and my portfolio page open but i ran into another issue i cant open older post( blog/page/2/) in my blog . please how can i fix this issue
I want to create single page template like u did for portfolio page .. for multiple custom type posts Kindly suggest which argument shall i pass for .. second parameter 'slug' .. So that it automatically detects the specific custom post types..
7:08 you're showing a config for summary list of all new "portfolio's" posts... I'm on seventeen theme, and before that moment everything goes fine. How do you think, what can be wrong... There's no any errors at all, but newly created "portfolio" posts can be opened only through direct link (while editing, for example) they are ok... But that summary list doesn't see any of them (( There's only wireframed blank page, with a header, an empty body with a page title, and a footer. Also, one different moment, in my case, all of those new posts are assigned to their own categories (which was created earlier, before of creation of that custom post types)
Hey Alex, I'm having some issues here with the permalink... The correct should be local.wordpress.com/portfolio, but its like: local.wordpress.com/?porfolio any ideia why?
Hello sir, I have a single page of website. "Home" Page is only page and it contains section like ...header,about,blog,testimonials,contact us and footer. I want to make editor page at admin side from which I can edit and modify each of section separately when I click on home page. How can I add my custom fields in that page for editing?
To activate Gutenberg Blogs you have to add 'show_in_rest' => true to the $args array. And also noticed you have to refresh the permalink settings by selecting save.
Hi Alessandro. So far,seeing this tutorial I am still not quite sure about the archive.php. Why shall I view a post as an archive?what is actually the purpose of the archive?
Hi, Thank you for the very helpful video series. I followed all the steps in this video step by step, but at the end my 'Work' page is blank. I tried changing the permalink settings to Plain and then again to Post name, but it doesn't help. What can be the problem? Thanks.
+Sl Dd That's sort of a common problem when you create a new custom post type. I suggest you to reset your permalinks, clear your browser cache and then set back the permalinks to what it was before. Happy Coding!
Great tutorial Alex, finally someone who knows how to explain things to us noobs :). The only problem I ran into was getting the pagination to work on a custom page template (Work page). When I limit the posts_per_page to be less than the one in Wordpress settings I just can't make the pagination to work (even to appear) and I tried every solution from StackOverflow. Can you help me out? Or just point me in the right direction? Tnx
Hi Alex - bit confused - does creating the 'works' page in admin, then associating it with the page-portfolio-template.php mean that you can safely delete the single-portfolio.php and archive-portfolio.php files?
+najmantube nope, those are 3 different things. The page template it's used to handle a single page, so by default it prints only the content of that page. Archive prints all the posts of that specific custom post type, while the single prints only 1 post from that post type. With that said, you can code the page in a way to print all the info you want, and avoid to use the archive or single, but WP comes with these ready to use templates and you should respect that logic. Cheers
Hi Alex - I followed your video and created a page-portfolio-template.php and added the custom post type logic (as per video). I can see that this takes the place of the archive-portfolio.php file while the single-portfolio.php file is still operative. So a further question is: what is the point of creating the page-portfolio-template.php? Why not just create an archive-portfolio.php and as you say, respect the WP system?
Sure, you can totally do that. WP has multiple approaches to different problems, so I always find useful to show how to achieve something with different solutions. It's up to you and the specific of your theme do adopt the most optimal solution for your situation. Thanks for asking and for learning thru my tutorials
OK Alex I see what you mean about there being multiple ways of doing things. Going to do the last tutorial tomorrow - then move on to your custom theme series - thanks for all the work you've done it's been a great help!
Sure you can. Probably those are a bit more advanced topics compared to the WP101 series, really basic and mostly for beginners. In the Premium theme development series I tackle more complex topics and advanced customization options.
Hi Alex, thanks for the tutorial... Do you have any specific tutorial on custom post fields? What do you think about the Advanced Custom Fields plugin? I'd rather prefer to code it myself, but I'm not sure about how complex would be to add custom post fields without the plugin. One of the plugin features I find more interesting is the ability to relate fields from different post types. I suppose that a typical example for this topic is a library, one post type would be "books", another would be "readers", and a third one "book borrowings". When a reader borrows a new book, the librarian should generate a new "book borrowing post" with at least two relational fields, one pointing the the "book" ID and one pointing to the "reader" ID. How complex would it be to implement something like that in wordpress without the ACF?
Hey! I have the same question as you about creating custom post fields by coding them myself. Did you ever find a tutorial to help you figure this out? Would appreciate it if you could share.
+Arete Did you refresh your hatches file by changing the permalink structure? Try to change the permalink structure to default, refresh your cache, reset your permalink to post-name and try again. Happy coding.
+Alessandro Castellani If I have default permalinks I am able to view the custom post by accessing it from the "View" button in the CP. But it does not work if I change the permalinks to Post name. Also the custom post does not list on the frontpage with all my other posts. I am not sure why. I have created the single-portfolio.php, archive-portfolio.php and page-portfolio-template.php
Mh, that is weird. It's definitely related with your .htaccess file. Try to manually delete the file if you can access your FTP and then regenerate your permalink structure. If it works with your default permalink it means that the CPT it's working properly and it's properly coded. If it stops working with a different permalink structure, it's most likely related with the .htaccess file. Don't feel frustrated and keep going, it's all experience. Cheers
Thanks so much for your reply! I use WAMP server (WP locally). I don't know if that is causing problems. The .htaccess is basically empty. (It just has # BEGIN WordPress and # END WordPress). Just so you know everything is displaying fine. Its just that the custom posts does not appear on the "homepage" or where the "normal posts" usually appear.
oh, do you mean in the post loop? If that's so, it's totally normal. a CPT is not included in the default post loop, you have to manually edit the query_post to include posts and custom post types
I'm having the same issue as jellocoding described earlier with 404 page coming up when I view item on the portfolio item. I changed the permalink settings to Plain (default?), cleared the browser cache and it worked. When I switch permalink settings back to "Post name", and the problem comes back - in addition my links to all my other menu items are now not working. Am I missing something? You mentioned deleting a file in your earlier post to jellycoding. Is this the htaccess file? I have a feeling this is something simple I am overlooking, but I'm not able to come up with anything. I will update here if I find the solution. Thanks!
+Bob S Yes, delete you .htaccess file in your main root. It's an hidden file in the same root where the wp-config.php file is. Let me know if you solve this issue.
+Bob S I did some reading on the WP Codex site and found that WAMP (which I'm using) does not enable mod_rewrite in the .htaccess by default. I made the required changes to the apache httpd.conf file (uncommenting LoadModule rewrite_module modules/mod_rewrite.s) and it works fine now. I even tried to break it again but it keeps on working fine. I'm not sure what this change actually did but I'm learning to navigate the wp codex for answers when I need them. I hope this info helps others who might run into similar problems. Thanks!
Hello, I've created a post type caled 'thestudents' then made a file called 'archive-thestudents.php' but when i put thesiteurl/thestudents the page that opens is the index.php as if it is not taking into consideration that there is archive-thestudents.php (note that i fixed meta links like you mentionned) what do you think?
+Hala Habka Do you have any post inside your new Custom Post Type "The Students"? If you archive is empty, the system could roll back to the index. Also, I suggest you to remove the article "the" from the slug of Custom Post Type. Try to always use one word like "students", or if you have multiple words, use a dash to separate them, like "the-students". Cheers
If your single-whatever.php or archive-whatever.php are showing a 404 or wont refresh after making changes this worked for me: Add flush_rewrite_rules(), refresh the page once or twice and REMOVE IT IMMEDIATELY. You SHOULD NOT keep flush_rewrite_rules() unless under the provisions as in the codex. nice tutorial!
Hi Alessandro! I was following your amazing tutorial but then got a 404 error when trying to display the portfolio entries. I deleted the .htaccess file as suggested on the previous comments but then the links to all the sections in the navbar broke :( Any suggestion? I'm using MAMP and unfortunately have permanently deleted the .htaccess file :( Thanks!!
Hi Alex! As usual, your videos are excellent! No matter If they were made 2 years ago, they are super useful!!!! For someone having the same problem as me that in the URL appears post: www.mysite/post/portfolio/name instead of www.mysite/portfolio/name I had to change inside the function, the argument: 'rewrite': 'rewrite' =>array('slug'=> 'portfolio'),
Hey Alessandro Castellani, its just an awesome video.. Just loved it.. Can you please help me , I want to add more than 1 custom post Type but its not getting feasible. Can you please give me the code or help me to do that. Waht I did was just copied this code and pasted it 2 times with different Post Names.. after updating it dont allow me to enter my wordpress loggin.. Can you help..
Hello Alessandro, I'm having a hard time displaying the category of custom taxonomy in my page can you help me? I'm developing a wordpress site with a team members but can't display the category but it displays all the team members. How can I display according to its categories? thanks and let me know?
Thansk Again For Your Amazing tutorials even i'm starting followign you later in 2017 ahahah , but Anymway i think i'm gonna be super master in wordpress by learning from you , i have a little question for you please if i don't disturb you . By Creating a new custom Page and linked it to a CPT page , automatically the single post page work by default , or i should create another single-slugname.php for the registered CPT ? Thanks In Advance .
You can create a dedicated single template by creating a file called single-slug.php which the slug is referring to the CPT slug. Otherwise, WordPress will use the default single.php and get the proper data automatically.
hi alex, i've pasted your portfolio custom post type code into my functions.php and it's ok but in the menu section i don't see the voice portfolio like you...how is it possible? thank you for your work
In my WP version i dont have Template activated yet so can choose . I have only Parent and order showing under Page Attributes. EDIT: So they change the location of the template dropdown to the beginning of the edit page in 6.3. I have no idea why it didnt wanna show in the drop down menu at first but i copy paste the first 6 rows from No Title template
I got stuck here. I do everything like you do and when I press View Item like you do about 6 min in the video I still get the 404 page. I started the vid from start and checked every step and I even have my code at the same rows as you have (LoL). I went to the github and copied your function.php code and still I get the 404 page. Ctrl-F5 - don't work and I did trash the page portfolio the way you did. Do you have any idea what I could try? I also tried the next step and duplicated the archive.php, renamed it and it also gives me the 404 page. :(
+jellycoding Hi, I had this problem too and it's a bit annoying. It's mostly related to .htaccess file and the fact that WordPress can't properly flush it. Try to manually delete that file, set your permalink structure to default, clear your cache, and then put back your permalink to whatever you want. Let me know, Cheers.
+Alessandro Castellani I only changed my permalink to default, updated my browser and it worked. Then I changed permalinks back and it worked again. Maybe I could just deleted my cache instead? Ahhh!! Nice and "super simple!"
hey Alessandro i did everything same as you but i was getting the 404 page so what i did to solve that was adding flush_rewrite_rules(); in the custom_post_type function, after refresh the post was show it right, it's this solution is good or will affect wordpress behavior? , also the remove version dint work for me so i use a suggestion from stack that say use this function myFunction_remove_cssjs_version($url){ return remove_query_arg('ver', $url); } add_filter( 'style_loader_src', 'myFunction_remove_cssjs_version' ); add_filter( 'script_loader_src', 'myFuction_remove_cssjs_version' );
Hey Alessandro, I managed to complete this tutorial but I am left with some questions :) Moving back and forth between the archive page and the static page I ended up with www.something.com/projects/ (project overview with custom query) and www.something.com/portfolio/project01/ (single-portfolio.php). How can I obtain www.something.com/projects/project01/ ? I find that switching the url from 'projects' to 'portfolio' is a bit confusing to the visitor. Is creating a custom navigation link to the project archive the only way? Or can I redirect .../portfolio/... requests to .../projects/... (just thinking out loud)? I also thought that www.something.com/projects/field01/ would work as a filtered project overview right away but it doesn't. Any ideas? Greetings
For this type of approach, I'd suggest you using a Custom Post Type. With a custom post type called "Projects", you'll automatically have the permalink structure you need and expect. Also, you will be able to create a page called archive-projects.php to style like your current static page. I hope that helps.
Hi Alex, Thanks for the tutorial. I am struggling to add new custom post types to my wordpres site without the help of a plugin. I tired the same steps as you showed in the video. To avoid error I simply copied and pasted your code to the functions.php of my website. I am able to see the "Portfolio" option on the dashboard but the published posts are not visible. In fact, posts of built-in post types are also not opening anymore. The pages are working fine though. My theme has two function files. "functions.php" and "functions-core.php" If I use CPT UI plugin the post types are working fine but I want to achieve it without using plugin. Please help :( Thanks in advance! Zubair
The htaccess file it's an hidden file by default, so if you can't view hidden files it's normal that you don't see. If you change the permalink structure, what does' WordPress say? It is returning an alert that can't update the htaccess file for you?
@ahmed hussin. Try to refresh your permalinks and the reload the page. I had the same error when I tried and think this is how I managed to solve .Not quite sure at this time
I can't seem to be able to use single-{post-type}.php for the custom post type template ): However archive-{post-type} works just nicely nice, and i find it intuitive enough. However, i would like to know why it doesn't work the other way 💔
Nice tutorial, i just walked in to WP and this is super usefull! If you want to add your custom link to your menu you can enter "/portfolio" without the quotes. When you click that link you will be redirected to www.yourdomain.nl/portfolio. When you move your theme to another domain your link will stay a little dynamical:)
hey brother , I have been doing the same as your tutorial suggest but in the line of permalinks there is no view item , get services link is shown and the permalink is like 'localhost/myFirstTheme/index.php/portfolio/signs/' and if i click on this link it sends me to 404 page can you explain me what is going on.
If you see *404.php* after clicking *view* it's all because of *permalink issues.* Super Easy & Simple solution (will work 100%) is just go to your *Dashboard then Settings -> Permalinks -> Save Changes* Reason: After creating a *Custom Post Type(CPT),* wordpress can't recognize those new links which you just created. So, we just need to refresh once that *permalink in settings.* Thank me later.
Hi Alessandro, Firstly I want to thank you for this GREAT TUTORIAL!!! Additionally, I want to let you know that the navigation links don't show up but I found this solution, maybe this can help other beginners that for sure still watching your videos: *Any feedback?
In case you have copied the single.php file and rename it to single-{your-post-type}.php and it is not working, go to the Permalink Settings in the dashboard and click on Save Changes for WordPress to refresh the permalinks. Now your template should be working.
Hi there, what is the address of the custom post type archive? localhost:7878/[slug] takes me to the index.php, not to the cpt archive nor to the cpt post-list
You don't have to use a custom static link. Appearance>Menus>Portfolio (dropdown)>View All and check All items, then change the label name to Portfolio and you're done.
Thanks so much for these tutorials - I really appreciate how detailed you are in your explanations, and how you slowly explain WHY you're doing things as you go. Super helpful!
Thank you so much for your positive comment. Sometimes I think maybe I'm going to slow and my explanations are boring.
I'm glad you find them useful.
Happy Coding
I also had issues with the portfolio page showing the 404 page.
I solved the problem by setting the Permalink structure to Post Name inside of the Permalink Settings (WordPress Admin Panel -> Settings>Permalinks).
- Update
Just noticed you mentioned it later in the course.
Hi, Alessandro!
I want to say THANK YOU!
You make really awesome videos.
Moreover you have a talent for explaining.
I really appreciate you and your work!
Oh wow, thank you so much :D
Alessandro Castellani, You are the Boss!
Ahaha, thanks :D
Thank you so much Alex! I learned from you more than from professor in college... Great explanations! Everything worked perfectly!
Alecaddd, I really love you :DDDD
I spent really a lot time to fix this issue. Your lessons the best.
Thank you so much!!!)
Thank you so much for watching and for the appreciation :D
Happy Coding!
thank you so much for the explaination of the custom post type sir.
You are most welcome
Hey Alex, if you want to add a link to the archive page all you need to do is go to Appearances -> Menus -> Portfolio and then click on View All, there you will find a checkbox that allows you to select the archive page for it in a dynamic way
+jacopo mazzoni Oh awesome, that is a functionality I didn't know existed.
Thanks for sharing!
+Alessandro Castellani yeah I found it because I couldn't get the custom archive page to work,
Turns out I didn't have a content-archive.php page, I added that and it all worked like a charm, I did not follow this from the beginning so probably you mentioned it in another video but not in this one so I was lost for a couple of hours there...
So if I wanted to I don't need to create a page template but I can simply edit the archive-portfolio.php page directly right?
+Alessandro Castellani one more question, did you make a video about hierarchical custom post types?
Could you make one? if you did could you link it in the reply? Thanks!!!!
+jacopo mazzoni th-cam.com/video/vSM7w3zzlSU/w-d-xo.html
Is there a way to limit the length of a custom post type (meaning allowing the post to be let say 250 characters long- not using the excerpt but limiting the actual post length)?
As usual, your tutorials are awesome!
Thank you so much!
thank you so much for this tutorial it is very helpful. may i ask for some question? how to display all the list of categories in the specific post type.
12:00 you cab actually add the portfolio archive by clicking the "add to menu" button :)
15.30 Would that be easer to export sql database replace the links and and import them back to db again ?
Hi, Alessandro.
I enjoy your videos very much - have some trouble with development environment being different to yours, but getting latest file(s) from GitHub helps. FYI - you are on a Mac using Safari, and am on Windows using Firefox,
This video (WP101 Part 19), suggests creating 'Work' as a template to make it dynamic when one has multiple custom post types. I didn't catch this 'dynamic' bit as you still coded 'Portfolio' itno array('psot_type', ..).
Incidentally, as the videos age i.e. you talked about Walker class when WordPress was version 2.x but is now 5.x. Is the Walker class really relevant any more?
Cheers,
Chun
Hi Alessandro, first of all, thank you for making these wordpress tutorials, I've learnt a lot with your videos! I have a question concerning wordpress theme. I want to create a one-page website with different layers (works, contact, gallery, ...) and I'd like to know from your point of view what kind of structure should I start with? I was thinking about using posts or pages that will be displayed in the front-page but I'm not sure if I'm in the right path...
I'd use pages for the different sections, in this way you can call everything with custom WP_Query directly in the index.php and build everything in one single page.
Sounds good, I'll start that way then. Thank you for your help!
I am still learning many things watching your videos
Hi Alex,thank you for your tuturials. They are amazing, as always. Would like to ask you, did you end up making the live dev session to style to pages as you said in the end of this tutorial?
I can't find it in your channel.
thank you.
+Jozef Sedlak Hi Jozef, thank you so much for following. Unfortunately I wasn't able to do the Live Session due to connectivity problems. Sorry about that
+Alessandro Castellani , Thank you for these perfect lessons! I learned a lot thanks to you! I have a question: If i want to add a widget with list of posts or archive from Portfolio (custom post type), what will I need to do? Thank you!
+Aleksandr Nadtochyi Hi, thank you so much for following.
The easy solution is to use a plugin, otherwise you have to code a widget from scratch. I've already planned that series, I will do that as soon as the current series it's finished.
Happy Coding!
ок! Thank you! You are the best!
Hey Alessandro, do you know any reason why the the 'post_per_page' argument would NOT be working. I havent gotten this to work at all. Whatever number is in the 'Blog pages show at most' Reading Settings in the Admin is the number blog posts that get shown. Any idea how to correct this?
can you please tell me how we can display custom post type by specific category(texonomy)?
Amazing tutorial! Is there another episode where you walk us through the styling too?
+Nathan Negative I just started the premium theme development where I will create a fully styled theme with Bootstrap. Thank you for following!
hello Alessandro i have changed my permalink and my portfolio page open but i ran into another issue i cant open older post( blog/page/2/) in my blog . please how can i fix this issue
You are the best italian guy in the world!
That's a pretty bold statement :D
I want to create single page template like u did for portfolio page .. for multiple custom type posts
Kindly suggest which argument shall i pass for .. second parameter 'slug' ..
So that it automatically detects the specific custom post types..
Hi Alex, i can't find the view post button in the post editor, did they changed it to a clickable permalink instead of a button?
7:08 you're showing a config for summary list of all new "portfolio's" posts...
I'm on seventeen theme, and before that moment everything goes fine.
How do you think, what can be wrong... There's no any errors at all,
but newly created "portfolio" posts can be opened only through direct link (while editing, for example)
they are ok...
But that summary list doesn't see any of them ((
There's only wireframed blank page, with a header, an empty body with a page title, and a footer.
Also, one different moment, in my case, all of those new posts are assigned to their own categories
(which was created earlier, before of creation of that custom post types)
Did you use flush_rewrite_rules() to refresh the permalinks?
Alessandro Castellani if you mean that sequence with move to URI as a ...post_id=X then backwards to human readable words -- yes, I've made that step
Alessandro Castellani or please provide a time code, where in the video, described that moment...
Because I'm cannot find it
Ales, WordPress doesn't show a template option in add a new page ?
WONDERFUL! Thank you for this (and part 1 of course), it made my week. Seriously.
Hey Alex, I'm having some issues here with the permalink... The correct should be local.wordpress.com/portfolio, but its like: local.wordpress.com/?porfolio any ideia why?
Featured images are not getting displayed in wp admin panel.. does label needs to be added for that $label array .. pls suggest
Hello sir, I have a single page of website. "Home" Page is only page and it contains section like ...header,about,blog,testimonials,contact us and footer. I want to make editor page at admin side from which I can edit and modify each of section separately when I click on home page. How can I add my custom fields in that page for editing?
Quick Question: How do you add a custom icon to your post type on menu?
To activate Gutenberg Blogs you have to add 'show_in_rest' => true to the $args array. And also noticed you have to refresh the permalink settings by selecting save.
I still got a 404 at 5:00. In the functions.php I had to add "
flush_rewrite_rules( false );"
Hi Alessandro. So far,seeing this tutorial I am still not quite sure about the archive.php. Why shall I view a post as an archive?what is actually the purpose of the archive?
Hi,
Thank you for the very helpful video series.
I followed all the steps in this video step by step, but at the end my 'Work' page is blank. I tried changing the permalink settings to Plain and then again to Post name, but it doesn't help. What can be the problem?
Thanks.
+Sl Dd That's sort of a common problem when you create a new custom post type. I suggest you to reset your permalinks, clear your browser cache and then set back the permalinks to what it was before.
Happy Coding!
thanks seen..you will be amazing with the website i have designed with your tutorials
Boss is you upload the live development session video?
Great tutorial Alex, finally someone who knows how to explain things to us noobs :). The only problem I ran into was getting the pagination to work on a custom page template (Work page). When I limit the posts_per_page to be less than the one in Wordpress settings I just can't make the pagination to work (even to appear) and I tried every solution from StackOverflow. Can you help me out? Or just point me in the right direction? Tnx
I dont have those view item and get shortlink nearby edit in the permalink section. Can you help me what did i do wrong in. Thankyou
Hi, Alessandro! custom post type page localhost/wordpress/portfolio/ is still showing archive of default post and recent post. How to solve this?
hi Alessandro, Thanks for the tutorial. can i ask u why my single-portfolio.php cant use? i copy your single-portfolio.php also cant use
Hi Alex - bit confused - does creating the 'works' page in admin, then associating it with the page-portfolio-template.php mean that you can safely delete the single-portfolio.php and archive-portfolio.php files?
+najmantube nope, those are 3 different things.
The page template it's used to handle a single page, so by default it prints only the content of that page.
Archive prints all the posts of that specific custom post type, while the single prints only 1 post from that post type.
With that said, you can code the page in a way to print all the info you want, and avoid to use the archive or single, but WP comes with these ready to use templates and you should respect that logic.
Cheers
Hi Alex - I followed your video and created a page-portfolio-template.php and added the custom post type logic (as per video). I can see that this takes the place of the archive-portfolio.php file while the single-portfolio.php file is still operative. So a further question is: what is the point of creating the page-portfolio-template.php? Why not just create an archive-portfolio.php and as you say, respect the WP system?
Sure, you can totally do that. WP has multiple approaches to different problems, so I always find useful to show how to achieve something with different solutions.
It's up to you and the specific of your theme do adopt the most optimal solution for your situation.
Thanks for asking and for learning thru my tutorials
OK Alex I see what you mean about there being multiple ways of doing things. Going to do the last tutorial tomorrow - then move on to your custom theme series - thanks for all the work you've done it's been a great help!
Hi Alex, Can I add custom field like "Price" in the admin (Add portfolio item). and Many thanks for this tutorial.
Sure you can. Probably those are a bit more advanced topics compared to the WP101 series, really basic and mostly for beginners.
In the Premium theme development series I tackle more complex topics and advanced customization options.
Hi Alex, thanks for the tutorial...
Do you have any specific tutorial on custom post fields?
What do you think about the Advanced Custom Fields plugin?
I'd rather prefer to code it myself, but I'm not sure about how complex would be to add custom post fields without the plugin.
One of the plugin features I find more interesting is the ability to relate fields from different post types. I suppose that a typical example for this topic is a library, one post type would be "books", another would be "readers", and a third one "book borrowings". When a reader borrows a new book, the librarian should generate a new "book borrowing post" with at least two relational fields, one pointing the the "book" ID and one pointing to the "reader" ID.
How complex would it be to implement something like that in wordpress without the ACF?
Hey! I have the same question as you about creating custom post fields by coding them myself. Did you ever find a tutorial to help you figure this out? Would appreciate it if you could share.
No matter what I do I can't seem to get the portfolio to display. I always get a 404 message.
+Arete Did you refresh your hatches file by changing the permalink structure?
Try to change the permalink structure to default, refresh your cache, reset your permalink to post-name and try again.
Happy coding.
+Alessandro Castellani If I have default permalinks I am able to view the custom post by accessing it from the "View" button in the CP. But it does not work if I change the permalinks to Post name.
Also the custom post does not list on the frontpage with all my other posts. I am not sure why. I have created the single-portfolio.php, archive-portfolio.php and page-portfolio-template.php
Mh, that is weird.
It's definitely related with your .htaccess file. Try to manually delete the file if you can access your FTP and then regenerate your permalink structure.
If it works with your default permalink it means that the CPT it's working properly and it's properly coded. If it stops working with a different permalink structure, it's most likely related with the .htaccess file.
Don't feel frustrated and keep going, it's all experience.
Cheers
Thanks so much for your reply!
I use WAMP server (WP locally). I don't know if that is causing problems. The .htaccess is basically empty. (It just has # BEGIN WordPress and # END WordPress).
Just so you know everything is displaying fine. Its just that the custom posts does not appear on the "homepage" or where the "normal posts" usually appear.
oh, do you mean in the post loop?
If that's so, it's totally normal. a CPT is not included in the default post loop, you have to manually edit the query_post to include posts and custom post types
How to add that single-portfolio.php via plugin rather than theme?
I'm having the same issue as jellocoding described earlier with 404 page coming up when I view item on the portfolio item. I changed the permalink settings to Plain (default?), cleared the browser cache and it worked. When I switch permalink settings back to "Post name", and the problem comes back - in addition my links to all my other menu items are now not working. Am I missing something? You mentioned deleting a file in your earlier post to jellycoding. Is this the htaccess file?
I have a feeling this is something simple I am overlooking, but I'm not able to come up with anything. I will update here if I find the solution.
Thanks!
+Bob S Yes, delete you .htaccess file in your main root. It's an hidden file in the same root where the wp-config.php file is.
Let me know if you solve this issue.
+Bob S I did some reading on the WP Codex site and found that WAMP (which I'm using) does not enable mod_rewrite in the .htaccess by default. I made the required changes to the apache httpd.conf file (uncommenting LoadModule rewrite_module modules/mod_rewrite.s) and it works fine now.
I even tried to break it again but it keeps on working fine. I'm not sure what this change actually did but I'm learning to navigate the wp codex for answers when I need them. I hope this info helps others who might run into similar problems.
Thanks!
Hello, I've created a post type caled 'thestudents' then made a file called 'archive-thestudents.php' but when i put thesiteurl/thestudents the page that opens is the index.php as if it is not taking into consideration that there is archive-thestudents.php
(note that i fixed meta links like you mentionned)
what do you think?
+Hala Habka Do you have any post inside your new Custom Post Type "The Students"?
If you archive is empty, the system could roll back to the index.
Also, I suggest you to remove the article "the" from the slug of Custom Post Type. Try to always use one word like "students", or if you have multiple words, use a dash to separate them, like "the-students".
Cheers
hi
why you use page template for show custom-post While you can do this by archive page ?
thx :]
If your single-whatever.php or archive-whatever.php are showing a 404 or wont refresh after making changes this worked for me:
Add flush_rewrite_rules(), refresh the page once or twice and REMOVE IT IMMEDIATELY. You SHOULD NOT keep flush_rewrite_rules() unless under the provisions as in the codex.
nice tutorial!
Hi Alessandro! I was following your amazing tutorial but then got a 404 error when trying to display the portfolio entries. I deleted the .htaccess file as suggested on the previous comments but then the links to all the sections in the navbar broke :( Any suggestion? I'm using MAMP and unfortunately have permanently deleted the .htaccess file :( Thanks!!
Why Template option is not showing in page attribute?
Hi Alex! As usual, your videos are excellent! No matter If they were made 2 years ago, they are super useful!!!!
For someone having the same problem as me that in the URL appears post:
www.mysite/post/portfolio/name
instead of
www.mysite/portfolio/name
I had to change inside the function, the argument: 'rewrite':
'rewrite' =>array('slug'=> 'portfolio'),
Great info, thanks for sharing
Alessandro Castellani thx to you!
after use your code. i am facing problem,
posts categories & custom post categories are same.. how to make it separate in wp-admin?
Hi. Thanks for the video. I copied and pasted functions.php from your GIT and then created single-portfolio.php but I get 404 error. Please help me.
Did you flush your cache and reset your permalinks?
I reset my permalinks and it worked. :D Thanks.
I'm having trouble with this part, I did everything correct but the post archive for the custom post type still not showing.
Hey Alessandro Castellani, its just an awesome video.. Just loved it..
Can you please help me , I want to add more than 1 custom post Type but its not getting feasible. Can you please give me the code or help me to do that.
Waht I did was just copied this code and pasted it 2 times with different Post Names.. after updating it dont allow me to enter my wordpress loggin.. Can you help..
Hello Alessandro,
I'm having a hard time displaying the category of custom taxonomy in my page can you help me? I'm developing a wordpress site with a team members but can't display the category but it displays all the team members. How can I display according to its categories? thanks and let me know?
Is this something related to my tutorials? If it is, you check my source code on GitHub. Cheers
Thansk Again For Your Amazing tutorials even i'm starting followign you later in 2017 ahahah , but Anymway i think i'm gonna be super master in wordpress by learning from you , i have a little question for you please if i don't disturb you .
By Creating a new custom Page and linked it to a CPT page , automatically the single post page work by default , or i should create another single-slugname.php for the registered CPT ? Thanks In Advance .
You can create a dedicated single template by creating a file called single-slug.php which the slug is referring to the CPT slug. Otherwise, WordPress will use the default single.php and get the proper data automatically.
Allright , Thanks A Lot , Now i Get It .
hi alex, i've pasted your portfolio custom post type code into my functions.php and it's ok but in the menu section i don't see the voice portfolio like you...how is it possible? thank you for your work
Already answered via email :P
hi Alessandro, i've the same problem like Lorenzo so can you please answer here or forward the same mail to me? (marko.lesnicar@gmail.com) thank you
Hi, guys, I can't make paginate my custom post with this method the last one the teacher show, using page template is something I miss ??
Did you check my source code on Github?
Great tutorial Alessandro, mille grazie!
Cheers
In my WP version i dont have Template activated yet so can choose . I have only Parent and order showing under Page Attributes.
EDIT: So they change the location of the template dropdown to the beginning of the edit page in 6.3. I have no idea why it didnt wanna show in the drop down menu at first but i copy paste the first 6 rows from No Title template
I got stuck here. I do everything like you do and when I press View Item like you do about 6 min in the video I still get the 404 page. I started the vid from start and checked every step and I even have my code at the same rows as you have (LoL). I went to the github and copied your function.php code and still I get the 404 page. Ctrl-F5 - don't work and I did trash the page portfolio the way you did.
Do you have any idea what I could try?
I also tried the next step and duplicated the archive.php, renamed it and it also gives me the 404 page. :(
+jellycoding Hi, I had this problem too and it's a bit annoying. It's mostly related to .htaccess file and the fact that WordPress can't properly flush it. Try to manually delete that file, set your permalink structure to default, clear your cache, and then put back your permalink to whatever you want.
Let me know,
Cheers.
+Alessandro Castellani
I only changed my permalink to default, updated my browser and it worked. Then I changed permalinks back and it worked again. Maybe I could just deleted my cache instead?
Ahhh!! Nice and "super simple!"
+jellycoding
...and now when I continue with the tutorial you do exactly this. LOL, I should just have watched a minute more ...hahaha!
hey Alessandro i did everything same as you but i was getting the 404 page so what i did to solve that was adding flush_rewrite_rules(); in the custom_post_type function, after refresh the post was show it right, it's this solution is good or will affect wordpress behavior? , also the remove version dint work for me so i use a suggestion from stack that say use this
function myFunction_remove_cssjs_version($url){
return remove_query_arg('ver', $url);
}
add_filter( 'style_loader_src', 'myFunction_remove_cssjs_version' );
add_filter( 'script_loader_src', 'myFuction_remove_cssjs_version' );
Yes, the flush_rewrite_rules() is the way to go.
Be sure to not hook that method on init, because it's really heavy and resource demanding.
Cheers
i am doing the same as you duplicating the single rename it to single-myslug.php and again throws 404.php
Hey Alessandro, I managed to complete this tutorial but I am left with some questions :) Moving back and forth between the archive page and the static page I ended up with www.something.com/projects/ (project overview with custom query) and www.something.com/portfolio/project01/ (single-portfolio.php). How can I obtain www.something.com/projects/project01/ ? I find that switching the url from 'projects' to 'portfolio' is a bit confusing to the visitor. Is creating a custom navigation link to the project archive the only way? Or can I redirect .../portfolio/... requests to .../projects/... (just thinking out loud)? I also thought that www.something.com/projects/field01/ would work as a filtered project overview right away but it doesn't. Any ideas? Greetings
For this type of approach, I'd suggest you using a Custom Post Type.
With a custom post type called "Projects", you'll automatically have the permalink structure you need and expect. Also, you will be able to create a page called archive-projects.php to style like your current static page.
I hope that helps.
Hi Alex,
Thanks for the tutorial. I am struggling to add new custom post types to my wordpres site without the help of a plugin. I tired the same steps as you showed in the video. To avoid error I simply copied and pasted your code to the functions.php of my website.
I am able to see the "Portfolio" option on the dashboard but the published posts are not visible. In fact, posts of built-in post types are also not opening anymore. The pages are working fine though.
My theme has two function files. "functions.php" and "functions-core.php"
If I use CPT UI plugin the post types are working fine but I want to achieve it without using plugin.
Please help :(
Thanks in advance!
Zubair
I tried deleting cache and changing the permalinks but it just don't work. And there's no .htaccess in the root folder.
The htaccess file it's an hidden file by default, so if you can't view hidden files it's normal that you don't see.
If you change the permalink structure, what does' WordPress say?
It is returning an alert that can't update the htaccess file for you?
Yes it is returning a message which says it can't change the permalinks automatically due to Read/Write rights on server.
Just like to point out that I always include a content template 404 if there is no content present to load using an else :
Thanks for the info
hey alex , after creating custom post type (portfolio) i made single-portfolio.php and when i preview post it shows 404 page ,, why that?
@ahmed hussin. Try to refresh your permalinks and the reload the page.
I had the same error when I tried and think this is how I managed to solve .Not quite sure at this time
i did it ,, thanx
Very nice tutorial. Thank you soo much!
You're very welcome, thank you for keep watching :D
Wat about the at the end of the code?
Yup, you're right. sometimes I forget it because doesn't interfere with other loops. Good call, I will add it next lesson!
why my post from costume post not showing in main page?
After you create a custom post type always flush the cache of your browser and your website.
fixed, but now how to display category in my costume post posting?
I have script like this
if (!function_exists('mh_magazine_lite_post_meta')) { function mh_magazine_lite_post_meta() { echo '' . "
"; echo '' . get_the_date() . '' . "
"; echo '' . esc_html(get_the_author()) . '' . "
";
echo '' . get_the_category_list(', ', '') . '' . "
";
echo '' . get_comments_number() . '' . "
"; echo '' . "
"; echo '' . the_views( false ) . '' . "
";
echo '';
}}add_action('mh_post_header', 'mh_magazine_lite_post_meta');
I can't seem to be able to use single-{post-type}.php for the custom post type template ): However archive-{post-type} works just nicely nice, and i find it intuitive enough. However, i would like to know why it doesn't work the other way 💔
Oh no no no, got it! Of course, single-{post-type}.php is for single posts from that custom post type n.n
Eheh, I'm glad you solved it :D
Nice tutorial, i just walked in to WP and this is super usefull!
If you want to add your custom link to your menu you can enter "/portfolio" without the quotes. When you click that link you will be redirected to www.yourdomain.nl/portfolio. When you move your theme to another domain your link will stay a little dynamical:)
hey brother , I have been doing the same as your tutorial suggest but in the line of permalinks there is no view item , get services link is shown and the permalink is
like 'localhost/myFirstTheme/index.php/portfolio/signs/' and if i click on this link it sends me to 404 page can you explain me what is going on.
If you see *404.php* after clicking *view* it's all because of *permalink issues.* Super Easy & Simple solution (will work 100%) is just go to your *Dashboard then Settings -> Permalinks -> Save Changes*
Reason: After creating a *Custom Post Type(CPT),* wordpress can't recognize those new links which you just created. So, we just need to refresh once that *permalink in settings.* Thank me later.
suggestion about visual composer
Elementor is the best for me, give it a try
Hi Alessandro, Firstly I want to thank you for this GREAT TUTORIAL!!! Additionally, I want to let you know that the navigation links don't show up but I found this solution, maybe this can help other beginners that for sure still watching your videos:
*Any feedback?
thanks for this it's very good
but I used this loop in home page it's not show why?
Check my source code on Github to see if you have any typos.
Cheers
In case you have copied the single.php file and rename it to single-{your-post-type}.php and it is not working, go to the Permalink Settings in the dashboard and click on Save Changes for WordPress to refresh the permalinks.
Now your template should be working.
Hi there, what is the address of the custom post type archive? localhost:7878/[slug] takes me to the index.php, not to the cpt archive nor to the cpt post-list
be sure to use flush_rewrite_rules(); to flush your cache, permalinks, and overall rules of your theme in order to get the new CPT working properly.
get_template_part('content', 'archive'); fetching nothing
what is the reason??
Check my source code on GitHub to see if you have typos or mistakes
You don't have to use a custom static link.
Appearance>Menus>Portfolio (dropdown)>View All and check All items, then change the label name to Portfolio and you're done.
keep running...thanks
just as an advice, add this code to header just for page debug
Thanks
Grazie Alessandro! sei bravo ;)
thank you this is awesome. :-)
How to add custom fields like excerpt.
Check my Premium theme development series to learn all about that
Godlike!
Why i am not able to create a new template like you did..
Did you check my source code on Github?
Niiiiiiice❤
nice tutorial.... #2019
custom post type portfolio page is redirecting to 404