• Hello everyone!

    I’m looking for some clues on how to build custom content type for my WordPress Site. I’ve been working with WordPress for quite a while now, mostly just building Websites and never really developed anything for it, but now I’ll have to (at least I think so!). I’m rebuilding an old Webpage we build years ago with Drupal and came across an old feature which seems to be a little complicated to rebuild.

    More specifically I’m talking about this one here:
    http://abitipps.de/organisation/abimottos/abimotto-sammlung/

    As you can see, on this site we’re having a rating system. We have a list of posts (they’re Mottos for when you finish school in germany), every visitor can upvote the posts they like the most (no limitation) and the posts get sorted automatically after the amount of votes. BUT you also got tabs where you can change the sorting, like:
    – when you click on “Kategorien” the posts are sorted in Categories (which the admin has to pick first, before he creates a new post)
    – then you also got an alphabetical order
    – and an order after which year the mottos got posted

    So in short:

    I need to create a list of posts, each can be voted by visitors, the amount of votes have to be saved forever (you can vote any year for any motto) and I have to offer the option to sort those posts after:
    – Amount of Votes
    – Categories
    – Alphabetical
    – The year they were posted

    Could someone maybe give me a little help/hint how I could develop that? I know I’ll probably have to work with custom content type and php, both never used, but I’m willing to learn. I’m not looking for someone to create this for me, as it’s a good way to strengthen my skills with wordpress and learn something new. But a little direction on how I should approach this would be very helpful! 🙂

    And yes I looked for existing WordPress Plugins, sadly none of them had exactly the features I was looking for. But if you do happen to know a plugin that has those features: I’m open to test it!

    Thanks to anyone who’s willing to help! 😀

    • This topic was modified 6 years, 6 months ago by unitasaurus.
    • This topic was modified 6 years, 6 months ago by unitasaurus.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Some reading for you:

    https://codex.wordpress.org/Post_Types

    https://codex.wordpress.org/Taxonomies

    and something to let you build the back-end stuff:

    https://www.advancedcustomfields.com/

    Thread Starter unitasaurus

    (@unitasaurus)

    @sterndata thanks for the fast answer! Gonna have a look at that 🙂

    Thread Starter unitasaurus

    (@unitasaurus)

    Alright, I read through everything and if I’m not wrong my approach should be now:

    – Create a custom post type as a plugin (not making it a must use plugin, since its only for one homepage) with all the actions it needs
    – Create an administration menu to give Admins the option to manage this plugin
    – Use custom taxonomies to group my post for the category feature

    Am I missing something?

    Moderator bcworkz

    (@bcworkz)

    A plugin is a good choice for custom code, though overriding theme templates from plugins can get messy. A child theme is usually better for custom templates, but it’s not efficient to do the same template on every theme of a multi-site installation.

    A CPT is a good way to separate particular content from the site’s other posts and pages. You then get a specific list table admin screen just for that post type. You may not need your own admin menu. You could maybe add bulk actions or action links to the list table instead. It depends on what administrative things you need to do.

    Instead of a CPT, you could isolate normal posts for a specific purpose by assigning a particular category, tag, custom field, or other taxonomy term to all such posts. But then you lose the dedicated list table admin screen.

    The sorting options that you want can mostly be achieved by altering the default query “orderby” query var in the “pre_get_posts” action, or by passing the appropriate &key=value pairs as URL parameters. The notable exception is you cannot use “orderby” to sort posts by assigned taxonomy terms. For that you need a custom SQL query. You can either modify the default SQL through the “posts_request” filter, or make your own SQL through global $wpdb methods. Thus, where possible, you may be better off organizing around custom fields instead of taxonomy terms. Fields do have drawbacks themselves compared to taxonomy terms. You’ll need to weigh the differences to decide how to proceed.

    To be clear, this lack of sort support is for sorting all posts by their assigned terms. It’s quite simple to get only posts with a particular term assigned and sorted by another column like date or author. I hope this helps you organize your thoughts and determine the best approach.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Creating own custom content type’ is closed to new replies.