Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

När behöver du en custom post type eller taxonomi i WordPress?

Anpassade inläggstyper och taxonomier kan utöka WordPress utöver dess standardfunktioner. Om du använder dem på rätt sätt kan de hjälpa dig att organisera din webbplats på ett mer effektivt sätt.

Men det är inte säkert att de alltid är nödvändiga, och du kanske undrar om du ska använda dem.

På WPBeginner strukturerar vi vårt innehåll med hjälp av anpassade inläggstyper och taxonomier för att göra navigeringen enklare för våra användare. Så vi är mycket bekanta med dessa funktioner och vet hur man använder dem för att optimera en webbplats.

Den här guiden hjälper dig att förstå när du ska använda anpassade inläggstyper och taxonomier och hur du maximerar dessa funktioner.

When do you need a custom post type or taxonomy in WordPress?

Vad är Custom Post Types i WordPress?

Custom post types gillar andra content types som posts och pages. En post type avser alla typer av content som du skapar på din website.

WordPress levereras med några olika post typer som standard:

  • Post
  • Page
  • Attachment
  • Revision
  • Nav-meny
  • Block templates (Patterns)
  • Templates

Observera: Det finns flera andra innehållstyper som används av WordPress bakom kulisserna för att tillhandahålla olika funktioner, t.ex. anpassad CSS, anpassa changeset, malldelar, oEmbed-cache och mer.

Inläggstyper hjälper till att skilja mellan olika innehållstyper i WordPress. Inlägg och sidor är båda inläggstyper, men de har olika syften.

Du kan också skapa dina egna post types, så kallade custom post types. Dessa är användbara när du skapar content som har ett annat format än ett standard post eller page.

Om du till exempel driver en WordPress-webbplats för bokrecensioner kommer du förmodligen att vilja skapa en inläggstyp för bokrecensioner. Den här inläggstypen kan till och med ha olika anpassade fält och en unik kategoristruktur.

Vi använder anpassade inläggstyper på WPBeginner på våra sidor Deals, Solution Center och Glossary.

Custom post type coupons page example

Många populära WordPress-plugins använder redan anpassade inläggstyper för att lagra data på din WordPress-webbplats. Här är några exempel:

  • WooCommerce – Adds en ”product” custom post type till din WordPress site.
  • WPForms – Skapar en ”wpforms” post type för att lagra alla dina formulär.
  • MemberPress – Adds a ”memberpressproduct” custom post type.

WordPress eCommerce plugins, plugin för directory, fastighetsplugins, receptplugins och andra använder också custom post types och taxonomier för att sortera content.

För mer detaljer, se vår guide om hur du skapar custom post types i WordPress.

Vad är taxonomier i WordPress?

Taxonomier används för att gruppera posts och custom post types.

Det finns två taxonomier i WordPress: kategorier och tags. Dessa är användbara för vanliga blogginlägg, men de kanske inte är lika lämpliga när du börjar använda custom post types.

Du kan till exempel skapa en custom post type som heter ”Books” och sortera den med en custom taxonomi som heter ”Genre”.

Sedan kan du lägga till olika genrer, till exempel Fantasy, Horror, Romance, Self-Help med mera. På så sätt kan du och dina läsare snabbt sortera böcker utifrån deras genrepreferenser.

Taxonomies sorting example

För mer detaljer, se vår guide om hur du skapar customize taxonomier i WordPress.

Hur vet du när du behöver en custom post type eller taxonomi?

Du kan teoretiskt sett add to alla typer av content i WordPress posts och sortera dem med kategorier och tags, men ibland är detta inte idealiskt.

Nedan följer några tecken som kan tyda på att du förmodligen bör överväga att skapa en anpassad inläggstyp, anpassad taxonomi eller båda:

  1. En del av det innehåll du publicerar ser inte ut eller känns inte som ett inlägg, till exempel vår sida med bloggkuponger.
  2. Ditt innehåll behöver inte vara en del av en kronologisk serie poster, som vårt WordPress-ordlista-avsnitt.
  3. Kategorier och taggar hjälper dig inte att gruppera och sortera det specifika innehållet, till exempel de specifika avsnitten i vårt kupongområde.
  4. Du behöver ytterligare fält för att kunna enter mer information med ditt content. Till exempel har vårt WordPress Solution Center olika sektioner med customize-fält.
  5. Den kan inte vara en del av dina pages. Till exempel är vår Blueprint-sida helt enkelt en page med flera undersidor.
  6. You need to display that viss content differently than posts or pages.

Låt oss nu titta på ett annat exempel från verkligheten. Anta att du driver en webbplats för filmrecensioner där du publicerar filmrecensioner och andra typer av filmrelaterat innehåll.

Låt oss säga att dina filmrecensioner har varit mycket populära bland din publik, så du vill göra dem bättre och lättare att navigera. Du kan förbättra dem genom att lägga till stjärnbetyg och göra dem sökbara efter skådespelarnamn, genre och mer.

I det här fallet måste du skapa en custom post type för film reviews och sedan add to en custom taxonomi för att sortera efter skådespelare och genre.

Detta gör att dina besökare enkelt kan bläddra igenom dina filmrecensioner istället för varje inlägg på din WordPress-blogg.

Ett annat typiskt exempel är att kreativa personer gillar fotografer och grafiska formgivare som skapar portföljer.

Om du bara delar med dig av ditt arbete i ett blogginlägg är det lätt att gå vilse i resten av ditt content. Genom att skapa en separat portfölj custom post type kan dina besökare enkelt bläddra igenom allt ditt arbete.

Portfolio custom post type example

Om du har olika kategorier av arbete i din portfölj kan du också skapa en customize taxonomi för varje typ av portföljprojekt.

Ytterligare resurser

Är du nybörjare på att bygga ut WordPress med egna taxonomier och inläggstyper? På WPBeginner har vi hjälpt WordPress-nybörjare under de senaste 16 åren.

Enligt vår erfarenhet är Följer några av de mest användbara resurserna för att hantera custom post types och taxonomier i WordPress:

Vi hoppas att den här artikeln hjälpte dig att förstå när du ska använda anpassade inläggstyper eller taxonomier i WordPress. Du kanske också vill se vår nybörjarguide om att byta eller konvertera anpassade inläggstyper eller kolla in dessa användbara handledningar om anpassade inläggstyper för ytterligare tips.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

21 kommentarerLämna ett svar

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Frank Luzón

    Thank you for this article, it helped me a lot!

    • WPBeginner Support

      Glad our guide was helpful!

      Administratör

  3. Rana

    A great article!!
    So now I want to learn custom field,type & taxonomy. From where can i learn properly all of these useful things.?? Plz suggest me any blog or YT channel or anything else..

  4. Amy

    Custom Post Types are awesome but something I’ve always wondered: how do you handle when or if you want to delete like for the sake of your example a ’single coupon’ from the CPT…. like you no longer need it or it’s not relevant anymore. Does this cause an error if someone clicks on it in search results if it indeed was showing up in search results; how do you handle properly deleting a specific item from a Custom Post Type? Or maybe you don’t delete it at first; you mark it with a Redirect possible? Would love to know how that should be handled properly :)

  5. arddev

    Hi, am I correct to think that your index(CT) has the same slug name as your ”glossary” CPT? Is there any possible conflict when a custom taxonomy has a slug the same as a CPT?

    • WPBeginner Support

      We do not need a custom taxonomy for our custom post type but if your custom taxonomy has the same slug then there is a chance it can cause issues based on your permalink settings.

      Administratör

  6. ADRIE

    What is ”Related Post-Meta Box”?

    Is that another way of saying, related post or related products?

    Or related categories/tags?

    • WPBeginner Support

      It is a custom taxonomy :)

      Administratör

  7. Tanuj Kalia

    Hi, I run a site, we have 14,000+ posts (all ’just’ posts) with NO ’custom posts’.

    The website has been running for 8 years now, and we have 250,000 unique visitors a month.

    We now want to convert some ’categories’ of the posts into ’custom posts’.

    How do we ensure that our URL structure (and SEO) is not disturbed?

    Thanks in anticipation!

  8. Snippet

    Great articles for those who are starting with wordpress.. I have a question: can a taxonomy be created only for regular posts in a category/several categories? and not with a custom post type…

  9. Steve

    I don’t know if these comments are still being monitored/responded to, but I just came across your article. I would like to do something analogous to your coupons pages, but add a feature where a reader can have an RSS feed or email notification sent to them whenever a new coupon is added to a specific category (e.g., Theme coupons, but not Plugin coupons, or vice versa). Could such features be added to a custom post type/taxonomy as a native WordPress feature or with a plugin? Thanks (for the article, and a possible reply).

    • WPBeginner Support

      All custom post types and taxonomies in WordPress have their own RSS feeds. This allows you to segment your email list(s). You can allow users to subscribe to your coupons post type or selected taxonomies under coupons post type.

      Administratör

  10. Laila

    Thanks for great ’plain English’ videos for non tech experts.

    I don’t think I need the extras that a custom post type plug in offers. If I should change my mind later in the development and implementation is it possible (without too many headaches) to add a custom post plugin at a later date and then categorize regular posts already made?

    Thanks.

    • WPBeginner Support

      Yes it is possible. But the difficulty level depends on what you want to do with custom post types.

      Administratör

  11. Gerard

    Great explanation. I’m developing a theme and I didn’t know how to separate the Testimonials section, the Quotes section, the Portfolio section, etc. Also, I will use it in a site where I review hostings.

    But I have a question about it: where is the information stored? If I make backups using a plugin, will the information be stored?

  12. Johan

    Can I store my custom post type in a new table, like wp_products instead to wp_posts. If yes, can someone point me in the right direction? Please. :D

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.