0

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.

6
  • 1
    The easiest way too do this is with custom post types and a custom taxonomy, otherwise your question is quite broad, narrow it down to a specific question so that it can be answered, otherwise it runs the danger of being closed as needing more focus, and less likely too get answers. You can always ask a second follow up question etc
    – Tom J Nowell
    Nov 13, 2020 at 20:27
  • You probably mean the database table, not the whole database? Anyway the Tom Nowell's suggestion is the best way to go, that way you'd be able to use all the WordPress features designed for working with the posts. Nov 13, 2020 at 21:00
  • I did mean table, Sorry. I will try to use custom post types and a custom taxonomy as you said. And will try to edit the question to make it more focused. Thank you both. Nov 14, 2020 at 7:46
  • @DavoodKazemi if your question doesn't get the answers you want, edit it to improve the question using the edit link so that it's clearer and easier to answer. Don't post the question multiple times on the site
    – Tom J Nowell
    Nov 14, 2020 at 18:07
  • Ok, Sure. Thought it wouldn't be seen by answerers if I edit the old question. Thanks for notifying. Nov 14, 2020 at 18:12

2 Answers 2

0

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:

1

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/

4
  • This won't give the OP a user interface, just a raw database table. For listing and categorising companies this isn't the easiest route
    – Tom J Nowell
    Nov 14, 2020 at 18:08
  • @TomJNowell valid point. The OP could create a custom post type and custom taxonomies, but the issue would remain the same. He still has to create more than 100 pages for each outlining the details of each company. Another route would be to create one page - using a custom plugin - creates a dynamic page that uses ajax and pulls data from the database to populate the single page. I think it depends on the exact direction the OP wants to go. I think both are valid approaches. Nov 14, 2020 at 19:09
  • You would need to construct all of that, your answer doesn't detail any that, please edit your answer to make that clear
    – Tom J Nowell
    Nov 14, 2020 at 20:55
  • @TomJNowell I made edits to the answer as suggested. Thanks. Nov 14, 2020 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.