Open leoloso opened 11 years ago
Thanks so much for all of your ideas and suggestions for Attachments! I've implemented them all thanks to your help but will need to think about this one. Storing redundant data would complicate the codebase quite a bit, but I understand your concern for performance. I'm going to think about this one in a bit more detail for the time being.
awesome! thanks to your for the plugin! :)
btw, I have my website already on a dev server, so you can see my Resources page here:
http://dev.mesym.com/en/resources/
This is the page I'd like to have paginated.
I'm mixing here with another issue, but it's handy to show it: in that same page, I added the possibility to also filter by author, I think it makes sense (in my website, the Resources are posted by users, so I display the info of who uploaded what Resource, then it makes sense to filter by author)
So I just added this: in function search():
if( $params['author'] )
$args['author'] = $params['author']; // avoid using 'p' or 'page_id'
and then when I do the search:
$search_args = array(
'instance' => 'attachments',
'fields' => $fields,
'filetypes' => $filetypes,
'author' => $users
);
This works perfectly
Hi Jonathan,
have you given a thought to this issue? I'll need to have a solution soon, I can possibly help develop it, but then of course I need you to tell me what you think is the best solution
Cheers, Leo
Hi @leoloso, I've just released a pretty decent update to the plugin that I've been working on for a while. Now that it's out the door I can spend some more time thinking about this. It's a sticky issue though due to the reasons you've outlined, but I'll see what I can do. If you'd like to fork the repo and have a play on your end I've love to see what you come up with too!
Hi, thx for your response. It's not in my plans to fork the repo and play with it right now since I'm overloaded with work, but I wouldn't mind helping you if needed, or try to do it myself in couple of months.
If I do it myself, I still need you to tell me what you think is the best solution. Right now I'm thinking aloud: I think the best would be that when saving the properties in DB, it shouldn't use json (since then you need to iterate through all the posts to find the ones you need), but instead save them as post meta data with a non-unique key "attachment", then you can easily filter in WP_Query which posts have attachments through condition EXISTS (since WP 3.5.1)
I'm not sure though how to save the other properties (attachment caption, description, etc): also in the post metadata (each property under a different (also non-unique) key, so it is also searchable, but then I'm not sure how to match each of these properties to its corresponding attachment), or as a term, or even under a new table
Understood. Given that any solution is going to involve changes to the data store in a very significant way, I likely won't be able to finalize a strategy for some time. Given that, if you'd like to stick with Attachments I'd suggest taking the performance hit, caching the result, and paginating on your end.
good, thx for your suggestion. I'll be waiting for feedback: whenever you decide on your strategy and need help, please let me know :)
Hi Jonathan,
I'm adding a new issue here to discuss the addition of pagination to the results of the search. I think this would be a wonderful thing to have.
As I explained in my previous 3 issues, I use Attachments to upload Resources to the post, like presentations, word files, or even youtube embeds (through plugin jwp6). Then, I have a page called Resources, where I select all the Resources from all the posts and display them all together. I attach an image of this page.
I would need to have pagination in function search(). However I was exploring the code, and I think it is not possible right now efficiently, because first you select the posts, and then from the metadata under metakey 'attachments' you select / filter the attachments. So let's say you want to paginate 20 results at a time, then you'd need to process all results, and then from the list just return 20.
The best way would be to already get the results, paginated, using WP_Query, so that the query wil alreadyl return the 20 values.
So I was thinking this strategy: In addition of what Attachments already does, saving the info under the post metadata under key 'attachments', also do the following:
As you can see, then you can also filter by post_mime_type already, and you can bring all results by not providing the $post_id
Also, you can add the id / title / caption / etc fields as a metadata field each and then also filter by them, for instance:
So what do you think?
Cheers, Leo