Storing Files for WordPress plugin - php

I am outlining a WordPress plugin that will take some information much like a blog post, including a featured image. I do not want to use actual posts, as this information really isn't part of the blog.
My question is about storing the "Featured Image" portion of this data. I would like to just put it in the database as a BLOB along with the other information on the record, but it doesn't seem that the $wpdb object is built to hand this data type.
So my question is this: How can I use the $wpdb object to insert BLOB data into the database OR is there a better alternative to using the database for this purpose?

Assuming you mean that the plugin will collect this information for multiple entities, it sounds like a job for Custom Post Types. That'll allow you to leverage all the functionality of posts (including feature images), but they won't pollute the blog.
There are also a variety of plugins that will allow you to generate custom post types via a UI rather than having to code them. For example, you might check out the Custom Post Type UI plugin.
If you just want to use the media manager to save a single image for the plugin (rather than one per entity), you could use a tutorial like Using the WordPress Uploader in Your Plugin or Theme to integrate the media manager into your own settings page.
Also, you're right that the WordPress database doesn't store images as blobs. WordPress saves uploaded image files to the wp-content/uploads directory, and stores a URI reference to them in the database for later retrieval.

Related

populate Wordpress page/post from external db - on the fly

After providing an event calender with PHP/MySQL/HTML/CSS I want to use Wordpress for that project from now on. Account and data management will remain outside of wordpress scope.
My best idea so far is to populate the posts (or pages) entirely from the already existing db. The URLs would be created by apache's rewrite engine.
To use one post and populate just the content would lead to really bad SEO.
So I want to create (virtually) unique posts populated entirely from the db. Extensive research on that topic brought up nothing usable so far. Maybe someone could point me in the right direction?
Preferences:
using mod rewrite to create the pages urls from event /ID/title rather than using the timestamps to create posts
keeping the data editable via external admin panel (no copying into WP-DB)
head data of post / page must be populated from db, e.g. title, author, timestamp etc.
Suggestions would be much appreciated, thanks in advance.
Have you tried the plugin WP All import. It creates unique post such are car listing etc based on the external DB. I also allows you to style and format your post.
https://wordpress.org/plugins/wp-all-import/

WordPress multiple content sections

Alright I am completely lost on how to do this so I am just going to throw the question out there and hope somebody can help me in some way or another.
WordPress offers the option to create custom Taxonomies so I got the idea of pulling something out of my hat and creating a custom content section apart from the content section wordpress currently offers.
The website shown above is the only website I have been able to find which currently does this and is on a WordPress platform, as you can see they have the SoundCloud audio player pushed over to one side with the actual content placed to the other side creating that flawless look.
I guess the question here is how can I turn <?php the_content(); ?> into something completely custom pulling from a completely different form in the back end so the same information is not shared.
There are numerous ways to achieve what you want.
Shortcodes
Custom page templates
Custom meta fields to store values like the soundcloud embed url, to afterwards use it in your code.
You can always also enter HTML in the page editor, but for obvious reasons not recommended.
Custom post types allow you to define a new type of content. It will have its own section in admin where you add and edit data separate from normal Wordpress posts. It can have its own templates allowing different layouts, and you can set up custom fields so that it can store different data.
I also recommend taking a look at the Pods Framework. This plugin allows you to define custom content types very easily in the admin interface. You can set up all your fields and data types from there. All that's required then is to create the templates to make it look nice.
The nice thing about these approaches is that while the data is kept separate from standard Wordpress posts, you still have the same familiar UI, so it's easy for none-technical users to update the content.

Pull content from a remote WordPress install

I need to create a wp widget that automatically pulls data from another wordpress install on a remote server.
Basically, the source site is a review site where offers vary over time. My widget will pull certain offers and make sure they stay updated.
Reviews on the source site are custom post types with custom meta fields that need to be fetched (price, offer, etc).
Looking around I've seen different suggestions: query the remote db, fetch the feed (does it store custom meta fields?), use json (which I barely know what is, but I am willing to learn new stuff).
What is the best method for my purpose and where can I find resources to help me achieving my goal?
Thanks for your help!
WordPress allows you to have an RSS feed per custom post type which is handy. Then you can make use of the WordPress Fetch Feed function to scoop what you need!
Are you the creator of the remote website?
You can create a new template in your theme
Code what you want to display in the format you want to display it
(json or just a bit of html)
In your wordpress admin create a new page and assign the new template
to it.
In your new site you just have to fetch the page

Wordpress custom post types and MANY images

I will be using Wordpress as a CMS with custom post types. Each "post" is a product and will have 20-60 images in 3 different sizes (60-180 total images per product).
What's the best way to link the images to the post?
I'm thinking about storing them on Amazon S3 and recording the URLs in custom meta tags, but I want to make sure I do it in a way that its easy to retrieve.
The WordPress has a built-in media library which has hooks that relate images to specific posts (products in your case). Given that a solid API exists for this, you may want to start there.
Helpful functions to look into are:
wp_insert_attachment
wp_delete_attachment
wp_get_attachment_image_src
wp_get_attachment_metadata
Update: To be more specific for this project, also be sure to look into add_image_size which allows you to define various thumbnail sizes which your posts can use. In other words, upload one large image and WP will automatically generate the rest. Mark J. of the WP team made a good writeup of the feature back wen 2.9 was released.
As for the S3, that definitely isn't a bad idea either, but keep WP as being your core source of data. Perhaps you can use a back-end process to move them to S3 and then update the attachment's metadata. When you render the post, check to see if a S3 URI exists, otherwise default to a local image.
(Disclosure: I'm not very familiar w/S3; but this is how I would start my quest.)

Can I use Wordpress just for the CMS UI, and pull using an API/raw SQL? (How?)

I have a small project for which I need to offer a CMS UI/storage system.
I am guessing that I can have my computer-fearing client use the Wordpress UI to store a set of images for her gallery page, and a set of text for her testimonials page. And then, through a Wordpress function, or raw SQL query into the database, I can get the data that I need on the page.
If this is possible, how do I do this?
We use the Pods CMS Wordpress plugin to help us create custom data fields for our site, for areas where the typical post/page structure just isn't appropriate.
Like everything else in Wordpress, Pods is a little rough around the edges, but it does provide a fairly simplistic interface for pulling information out of a database, without the need for raw SQL, or bolting together custom fields for a post.
A simple example for looping over records might look like:
$mypod = new Pod('mypod');
$mypod->findRecords('date ASC', 15) // ORDER BY date ASC, LIMIT 15
while ($mypod->fetchRecord()) {
$image = $mypod->get_field('image')
...
}
It also supports a basic set of relationships between Pod objects.
You can either just create your own theme/template for Wordpress, or you can create your own frontend altogether with raw SQL queries. The database layout is rather simple so it shouldn't be impossible to create your own system.
But consider the theme solution first because I think it's both easier for you (not needing to reinvent the wheel) and better for security (easy to use the built-in functionality for security updates).
So, WordPress 3.0 is getting to the point where it is no longer just a blogging platform, but almost a fullblown CMS. For her testimonial pages, or about me, contact, etc, you can use WordPress. Instead of creating new entries, just have her (or you) create pages.
For the gallery, there is an open source project called Gallery that you can use that would allow the client to upload and manage their own photos. In WordPress, just create a new menu item and link to the Gallery installation you have.

Categories