For me this is quite hard to do, but I guess that this could be easily done by an expert. :)
Let's suppose I have a post, which is a custom post type resources
, with the following data:
- Post Slug: beach
- Custom Fields:
dl1file
: bikinidl1link
: assets/file1.zipdl1count
: 56dl2file
: beachballdl2link
: assets/file2.zipdl2count
: 31
The post above have more than one file to download, and all of them are stored in Custom Fields as dlNfile
, where N
are numbers (e.g.: dl1file
). Also, each of these files have two more custom fields, the dlNlink
(e.g.: dl1link
) which will be used in the URL, and dlNcount
(e.g.: dl1count
) will store the download count number.
Now, with Rewrite API I will need to convert site.com/?resource=beach&file=bikini
(or if it's easier, site.com/resources/beach/?file=bikini
) into site.com/download/beach/bikini
.
When one of the links is clicked, and since I only provided the resource
, which is the post slug, and the value of one of the dlNfile
, WordPress will now have to know which post to retrieve and identify the correct dlNfile
, which in this case is dl1file
. Then it will know that the real filename is stored in dl1link
and then it proceeds to the download (site.com/assets/file1.zip
) and increments dl1count
by 1.
EDIT: I tried Jesper's tutorial before, but I don't want to create a new post just for store a download file information.
I also provided another URL idea, which doesn't have to store the URL parameter resource
, which is the post slug.
site.com/resources/beach
).