SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting and pulling custom posts to and from a custom table

    I've worked with a little php, but am by no means an expert. I've created a custom post type in which I'm going to use to store a list of names and emails. These aren't users, on a larger scale it's going to be used to extract who to send a dynamic email to.

    In any case, I've gotten far enough that I have the custom post set up in admin, but I'm not sure how to save it into or pull from a separate table. I'm using meta_boxes as well to create custom fields for the entries. I would prefer to send all of this info to my custom table without it interacting with wp_posts or the wp_meta_posts tables. I know that this can be done with old fashioned MySQL commands, but I think it would be best take advantage of the already built in behaviors that posts have. I've come across many things on the web that recommend to just keep with those tables, but the tables (at least the wp_posts table) is already overrun with information from regular posts. Is there a feasible way to do this? Do I use the wpdb command to do so?

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Use WP_Query and the post_type attribute. The post_type will be whatever string you used when you registered your custom post type.

    https://codex.wordpress.org/Class_Re...ype_Parameters
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Force Flow View Post
    Use WP_Query and the post_type attribute. The post_type will be whatever string you used when you registered your custom post type.

    https://codex.wordpress.org/Class_Re...ype_Parameters
    I think I see how this relates to custom post types, but I'm not really sure how it would with a custom table? I've not been able to find any example online that looks like what I want to do. I wanted to use the custom post method as it seems to do a lot on the admin side, but I'm not really sure as to how to specify those "posts" to go to a separate table

  4. #4
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by NT_cookies View Post
    I think I see how this relates to custom post types, but I'm not really sure how it would with a custom table? I've not been able to find any example online that looks like what I want to do. I wanted to use the custom post method as it seems to do a lot on the admin side, but I'm not really sure as to how to specify those "posts" to go to a separate table
    Are you saying you added custom posts to your own table, or that you want to?

    Wordpress has built-in mechanisms in place so that you shouldn't need to touch the database directly, or manually add custom posts to a separate database table. The proper way to do this would be to register your custom post type, set up your custom fields, and query the post type to get the data back out.

    If you are storing user information for an email list, try finding a plugin that will do this, instead of writing something from scratch. Maybe something like this: http://wordpress.org/extend/plugins/mail-list/

    Or, you don't even have to do this in wordpress. Maybe something like http://www.phplist.com/ or http://dadamailproject.com/
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not opposed to using a plugin, but haven't really found one that fits within my needs.

    I want the list info to go to a different table as the posts table is a mess from how they have the site set up.:


    Here's what I'm looking for in the long run whether I have to write it, or incorporate a couple of plugins to do it:

    The site is a franchise site, with several individual store pages within the same site. I want to create a Contact form that sends dynamically to each store owner according to which store it is.
    I'd also like to create the admin section, that I'm working on now so emails and contact names are editable within the admin.

    The plugin you mentioned seems to be more specific to customers instead of people with back end privileges. That's why I have my doubts that it would fit in with my needs.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •