How to make a list of companies’ information and display them to user, using custom post types and a custom taxonomy?

I need to add a list of companies’ information to my website and I want to display the list in a page. Then by clicking on each company, user can see more information about that company in its individual post.

What is the right approach for doing this? I researched about custom post types and custom fields. But they seem to be not right for me. Do I have to build a post for each company? They are more than a hundred. Is there a more speedy way to do this?

P.S The companies has identical fields. Each company has a name, description, etc and also has a few photos.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Custom post types and taxonomies are the appropriate method of doing this. It sounds like you’ve already identified the appropriate taxonomies and CPT:

  • A company post type
  • A company_type taxonomy

register_post_type and register_taxonomy can do this for you. Don’t forget to re-save permalinks if you use those functions or change their parameters.

After doing this, new sections will appear in the Admin sidemenu, as well as frontend listings, and theme templates.

Further Reading

Generators:

Method 2

That is a fairly open-ended question. There is a lot you will have to do. The first step is you will have to create the database. It will look something like this:

function db_install() {
    
    global $wpdb;
    global $db_version;

    $table_name = $wpdb->prefix . 'thenameofyourdatabase';

    $charset_collate = $wpdb->get_charset_collate();
    
    $sql = "CREATE TABLE $table_name (
        user_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
        first_name tinytext NOT NULL,
        last_name tinytext NOT NULL,
        type_of_work text NOT NULL,
        PRIMARY KEY  (user_id)
    ) $charset_collate;";

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );

    add_option( 'db_version', $db_version );


}

You will need to add more tables to match your created database.
This should get you started…you can read here for more information: https://codex.wordpress.org/Creating_Tables_with_Plugins

After this, since this will not provide you any user interface, you will need to create that. One method is creating a custom plugin – using the code above – as well as (I would suggest) jQuery. You would use jQuery to talk with the database, via AJAX, and populate the contents of the page.

One reason this may be a good option is the user will not need to refresh the page – they can gather all the data from all those companies from a single page.

Both methods would take work – if you go with the custom post type/custom taxonomies – you will need to still create those over 100 pages. If you go with the plugin, there is a good amount of work ahead in setting that up. Both require some work, so it depends on your preferred method.

If you want more information on jQuery and AJAX here are some references to get you started:

https://developer.wordpress.org/plugins/javascript/jquery/

https://developer.wordpress.org/plugins/javascript/ajax/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x