Support » Fixing WordPress » Converting a custom php/mysql script to WordPress

  • Hello guys.

    I need help converting a custom script I made. I only need to convert the categories AND the articles.

    My custom script uses a pretty simple db structure. One table for categories (cat_id, cat name, cat description, cat order), one for articles (id, article title, excerpt, text, link to picture), one for article_categories (where I tell which article has which categories).

    I tried installing a fresh WordPress and figuring out which tables are related to which, but I couldn’t really figure it out.

    So, could someone help me out, create a “formula” query, i.e. a query for ONE single article to be complete. Like, what would you manually insert to a database if you where to manually post a new blog article (not from admin). Then I could just create a php script to repeat that (batch) with data from my database.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You wouldn’t want to do direct UPDATE queries to make post and category entries in the WP DB. One could, but it’s rather complicated. It’s better to use WP PHP functions intended for that purpose. They take care of all the niggling details.

    Decide if you want your articles to be pages or posts. Pages can have a hierarchical structure and it’s fairly simple to assign different page templates to various pages. Posts don’t do this. You could also create a custom post type if you have another need for posts and pages.

    Whatever the post type, use wp_insert_post() to do the article insertions. In a similar vein, use wp_insert_category() to add category terms. To associate a particular term to a particular post, use wp_set_post_categories(). The other two functions need to be called before you can associate the two objects with this function.

    You mentioned your articles have a link to a picture. This is probably the same as a “featured image” in WP. The functions for featured images still use the older name “thumbnail”, as in set_post_thumbnail(). Before you do that, the image needs to be associated with a “attachment” post type. Use wp_insert_attachment() for that.

    The thumbnail moniker is misleading, which is why the label was changed to featured image. These “thumbnails” can be any size. These days they are often quite large. It would be an unusual theme to have actual thumbnail sized featured images.

    Not all themes necessarily support featured images, though I think most do. If yours doesn’t, it’s not all that difficult to add support. Declare it with add_theme_support() and configure the templates to output the image with the_post_thumbnail() or similar.

Viewing 1 replies (of 1 total)
  • The topic ‘Converting a custom php/mysql script to WordPress’ is closed to new replies.