custom-post-type | A base class for WordPress custom post types | Content Management System library
kandi X-RAY | custom-post-type Summary
kandi X-RAY | custom-post-type Summary
This is a base class for WordPress custom post types. For something that might be easier to use, try Post Types Creator or Extended CPTs. This is -not- a UI, nor is it intended to be. If you are looking for that, then try Custom Post Type UI. Other good resources: Custom Post Type Permalinks, Simple Post Type Permalinks. I have seen quite a few different ways of how people handle custom post types in wordpress, but was never really happy with any of them. They all did what they were designed to, but never really seemed to cover the things that I needed. So I set out to make my own. It is still very much a work in progress. Please drop me a note if you find it useful in your own projects. The basis for a lot of the code originated from different places on the web. I have tried to give credit where I can. My coding style can not be considered 'orthodox' in any way, shape, form, or fashion. WARNING: Use a permalink of /%category%/%post_name%/ otherwise this thing may not work at all...8-( It is something I am working on.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Register taxonomy registration .
- Apply attributes .
- Add address meta box
- Render the tabbed form .
- Map the meta capability .
- Render gallery gallery
- Save meta box
- Reduce object to array
- Rewrite rewrite rules .
- Create a new page .
custom-post-type Key Features
custom-post-type Examples and Code Snippets
Community Discussions
Trending Discussions on custom-post-type
QUESTION
I am using Contact Form 7 (5.4) and CF7 Smart Grid Design Extension (4.10.0) in a submit form on my WordPress site to construct draft Custom Post Types. The original inspiration for this was this awesome SO post.
The submission form has worked well and reliably for over a year, but with the new CF7 5.4 version, something has changed internally and broken image uploads. All of the other fields have remained unchanged.
The CF7 field with which I am uploading appears as
...ANSWER
Answered 2021-Apr-04 at 11:18Most likely, this issue is the same one I've faced. It appears that the Developer of CF7 decided it was better to make $uploaded_files['something']
into an array. Which probably breaks anyone's plugin that taps into this feature. Not the first time he's changed from a string to an array.
Anyway, this may solve it for you.
Changing this:
QUESTION
In the WordPress theme my team has developed, we've recently run into an issue where no matter what, when trying to exit a Post/Page/Custom-Post-Type, WordPress will throw up the warning, "Leave Site? Changes you made may not be saved." Even if you click update and then immediately try to exit the page, it will throw that warning.
I cannot figure out what is causing this. This behavior started when I pushed out a major update a couple of days ago. I tried completely removing that update, reverting all the changes via git, and the behavior persists. I even switch to a branch of the theme that hasn't been worked on in months, and the behavior persists.
I've tried Chrome, Firefox, Edge, and the behavior persists. I've had coworkers try it on their computers s, and the behavior persists.
It's driving me crazy! Does anyone have any advice even where to start looking? Is it just a recent WordPress issue and nothing to do with our Theme?
...ANSWER
Answered 2021-Feb-06 at 07:57This issue is caused by a bug that was introduced in version 5.6.1 of WordPress.
As a workaround, you can temporarily downgrade WordPress from 5.6.1 to 5.6. One way to do that is by using the WP Downgrade plugin.
Alternatively, you can just ignore the issue for a few days/weeks until they patch it.
QUESTION
I'm working on a site where the user can add videos to a slider using a custom post type. In reality, there are three different sliders and the videos that go inside each are determined by the category they're assigned. Here's the code that registers the cpt:
...ANSWER
Answered 2020-Oct-24 at 18:34'taxonomies' => [ 'category' ]
is your way of calling register_taxonomy_for_object_type( 'category', 'custom_type' );
but by removing that, you remove the taxonomy from the post type, not just the menu.
I'd suggest you register a custom taxonomy for your videos and assign admin capabilities to it.
Registering taxonomies: https://developer.wordpress.org/reference/functions/register_taxonomy/
The capabilities
option will allow you to only allow admins to alter them, so your capabilties
would look something like this.
QUESTION
I'm honestly getting pretty lost, and could use some guidance to wrap up a project I've been working on
I have a single hierarchical taxonomy, county that I'm using on two of my custom post types, floorplan and ready-made.
I am trying to set up permalinks to the custom taxonomy pages that will display as:
{post-type}/{parent-tax}/{child-tax}
Right now, you can navigate to either or, so floorplans/{parent-tax} and floorplans/{child-tax} will lead to the same county-taxonomy.php template. You can do the same for ready-made/{parent-tax} and ready-made/{child-tax}.
However, if you are going directly through the taxonomy, and you navigate to the child taxonomy, the url will display as county/{parent-tax}/{child-tax}.
What I can't figure out, is how to append the parent taxonomy to the child-taxonomy permalink when you're navigating by the custom post type base. floorplans/{parent-tax}/{child-tax} and ready-made/{parent-tax}/{child-tax} is a 404.
Do I need to write a rewrite rule? I'm kind of at a loss on how to do that. I followed along heavily with this guide in order to get my parent and child taxonomies displaying in the post type permalinks themselves, but the final piece of the puzzle is to be able to navigate to the child taxonomy pages specific to each post type, and include the parent taxonomy in that url.
My rewrite rules as of now look almost identical to the guide I linked,
...ANSWER
Answered 2020-Jul-15 at 16:05to answer my own question,
here is the final rewrite function in order to achieve the desired results:
QUESTION
I'm currently working on a WordPress site and I've created a custom post type called 'events' using the CPT UI plugin.
I want to display the events on my home page, so I've tried to create a loop in my homepage template in the theme files. I've been using this as a guide https://www.wpbeginner.com/wp-tutorials/how-to-create-custom-post-types-in-wordpress/
but for the life of me, I can't get the PHP that is used in that link to work for me.
...ANSWER
Answered 2020-Jul-01 at 13:25You have not end while loop , place this code also
QUESTION
i got a big Problem and have no Solution. i work with WordPress and Custom-Post-Type (CPT) and Advanced Custom Fields (ACF). I create a new CPT called "projekt" and a ACF "Google Map Field" which saves the Adress, longtitude and latitude. The bad thing is ACF Fields were saved serialzed in the MySQL DB.
i found the following SQL-Query on the Net to calculate the Radius.
...ANSWER
Answered 2020-Jun-20 at 23:50OK, so this looks pretty nasty but in testing with out adding the radius portion Im able to extract the lat
and lng
from the serialized data.
So I think you can tack on your radius check as an AND
something like below:
QUESTION
This relates to a post I made here
where initially I was interested in WordPress taxonomies
, but the more I think about my case, the more I think a custom table
approach makes sense.
So I am curious if there are any database experts who can advise me on table structure given my scenario:
I am setting up my site so I can teach guitar courses
. Perhaps of importance, I will not have many courses. Maybe 4-8.
Under a given course
, I have
ANSWER
Answered 2020-May-12 at 22:41These obstacles are intellectual; matters of understanding, not matters of implementation.
Noting the
Relational Database
tag.
Yes, a Relational database will give you:(a) the structure you are seeking, in straight-forward logic, as well as:
(b) the easiest code and the fastest queries
(that which you have requested, plus any that you dream up in the future).
.
But you have to use Relational concepts (the Relational Model by Dr E F Codd).
If you use the concepts marketed by Date; Darwen; et al, which is marketed as "relational", both the structure [a], and the code for navigation and queries [b] will be horrendous. Additionally, you will not have Relational Integrity; or Relational Power; or Relational Speed that is possible in database that complies with Codd's Relational Model.
The Relational Model is Hierarchic.
Three types of Data Hierarchies are formally (by prior intent and design) in the Relational Model.Your requirement is the simplest, four tables in a simple data hierarchy, which is reflected in the Relational Key (more, later).
The second type is a Tree (Single-Parent). You have that in Post, thus it needs no further explanation..
The third type is a Tree for Ancestors and a Tree for Descendants, without duplicating any data. Usually called a Bill of Materials structure. We don't have to worry about that here, it is beyond the scope of the question.
Warning. The links given in the comments will take you down a complex garden path, that might possibly be relevant for the other two types of hierarchies, and in any case, very poor implementations thereof.
Eg. SQL has recursion; MySQL does not have recursion, so a hard-coded and limited method is given).
Eg. some of the methods implement the trees in concrete: if a branch is moved, the entire tree needs to be re-written.
The point is, you don't need it. (You might need it for Post, but not for the answer to your question.)
You have an excellent grasp of your data, which is required for the exercise. But you have fixed ways of thinking about that data, no doubt due to the other implementation methods that you have tried, and the requirements therein. So the demand here is to give those methods of perceiving the data up, and to follow the Relational requirement:
- perceive the data, as data, and nothing but data
No additional columns or structures
To differentiate
Date; Darwen; et al, take the Result Set (the output of a query on Relational tables) as the starting point, as the perspective to be used when analysing and modelling the data. Which is reversing the order of nature, and guaranteed to cripple the modelling exercise (the report you want for a particular purpose vs the data as data).Then, as if stuck in an Excel spreadsheet mindset, they add on a
Record ID
field to the Result Set. Such an act cripples the modelling exercise further, because one now the false notion that a physicalRecord ID
identifies the logical row. It does not.- perceive the data, as data, and nothing but data
If you can give that fixed perspective up, along with the additions that contaminate the problem, and cross over the line into the Relational paradigm:
You will not need the
relations
table: it is totally redundant, because the Relational database supplies all relationships (that you have defined thus far).You won't need the
IDs
, which are always one additional field and one additional index on every file. And the horrendous consequential problems.
Additionally, you will obtain:
- Relational Integrity (which is logical, as distinct from Referential Integrity, which is the physical feature in SQL);
- Relational Power (your navigation and query code will be dead simple,
JOINs
of distal tables will not require intermediate tables to beJOINed
, etc); and - Relational Speed (fewest indices).
If interested, some of my recent Answers contain details and examples of those benefits.
NotationAll my data models are rendered in IDEF1X, the Standard for modelling Relational databases since 1993.
My IDEF1X Introduction is essential reading for those who are new to the Relational Model or Relational data modelling.
Rather than the example data you have given at the top of your question (which is not really example data, but a simple definition of the Form that you would like the display of the data to take), examine the example data (which are, of course, Identifying Keys) that I have given (blue).
- The numbers are redundant. if actually necessary, they can be computed on the fly
- Do not use numbers as Keys, because, when the structure changes, you will have to renumber all your Keys. Totally unnecessary.
The Relational Model demands that the Keys are "made up from the data". The numbers are not.
The data hierarchy is both:
visual in the data model
and reflected in the Relational Keys.
Relational Keys
- are composites, get used to it. SQL has been handling composite Keys since 1984.
- define and implement the data hierarchy. No surprise, because the Relational Model is hierarchic.
Course, Lesson, Topic, Quiz
are Key elements, short names, not necessarily codes (they would be codes in a large university), that are unique in the given context.The
Title
would be the long name that shows up on screens for external users (prospects).A
Lesson
does not exist independently, it exists only in the context of aCourse
. Therefore the Key forLesson
is (Course, Lesson
). AnID
does not uniquely identify aLesson
(or anything else, for that matter). You might have more than oneLesson
across theCourses
.A
Topic
does not exist independently, it exists only in the context of aCourse
and aLesson
. Therefore the Key forTopic
is (Course, Lesson, Topic
). Etc.A
Quiz
does not exist independently, it exists only in the context of aCourse
, aLesson
, and aTopic
. Therefore the Key forQuiz
is (Course, Lesson, Topic, Quiz
). Etc.
Relational Integrity
Eg. A
Quiz
is constrained to a particularTopic
, which is Identified by (Course, Lesson, Topic
).Whereas a
Record ID
based filing system (falsely marketed as "relational") cannot provide that, it can only constrain aQuiz
to anyTopic
.Of course, that applies to all the tables in the data hierarchy.
The relationship between Posts and the structure that is the answer to the question, is not at all clear, therefore it would be incorrect to model it. Nevertheless, it is important to you, so I have modelled it on a possibility basis, with reticence. If you define with more clarity, I will update the data model.
Dead simple, compared to that which you have in the fiddle, or that which is demanded by a Record ID
based filing system.
Get me all lessons for a course
QUESTION
Hej, i want to Display all Posts from one Category of my Custom Post Type with a Shortcode.
Example:
My-Custom-Post-Type: Tomatoe, Lettuce, Fruit, Vegan, Medium Rare, Rare
Food-category: Burger, Pizza, Salad
Burger: Vegan, Medium Rare, Rare
Salad: Tomatoe, Lettuce, Fruit
Is there a way to do this? Sorry for bad Example
...ANSWER
Answered 2020-Apr-30 at 10:19From your example I think you have confused CPTs with Taxonomies and Terms, but in general all you have to do is first create a custom shortcode by adding this in your functions.php:
QUESTION
I'm using the plugin CPT UI. I want to display the category name and under that the post that belong with that category. I want it to look like this. enter image description here
I would like to repeat this for every category so whenever a new category is added it will show the category name and the related post on the page. I have tried this so far
...ANSWER
Answered 2020-Mar-12 at 15:14You need to loop through all the terms (categories) and setup the query in each one:
QUESTION
So I want my posts in my custom post type deleted permanently instead of moving to trash first. so I found this code online that is supposed to do the trick. But I'm not able to get it to work somehow.
The code that I have is as follows.
...ANSWER
Answered 2020-Feb-27 at 15:26In your other post, it said your post type is called 'members'. You're instead checking for 'directory' type posts. Change the if-condition like so to actually affect the correct post type:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install custom-post-type
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page