The pluginplug-in, with two additional SQL queries, joins the original data sample $wp_query->posts all meta fields, all files and images, for each image the direct url to small, medium, and large image is formed. There’s no need to use functions the_post_thumbnail and get_post_meta.
So let’s say we go to the home page of our blog, WordPress gives us a list of the latest 10 records. Let me remind you these are already in the global object in the array $wp_query->posts. Let’s begin from creating a list of ID (number of records to which they are stored in the database).
Form the first SQL query:
$query = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN('21','29','30','35','38','42','46','48','49','55') AND $wpdb->posts.post_parent
AND $wpdb->posts.post_type = 'attachment'";
A normal translation is «find all the child entries for entries with the numbers (’21 ‘, ’29′, ’30 ‘, ’35′, ’38 ‘, ’42′, ’46 ‘, ’48′, ’49 ‘, ’55 ‘)». And the type of records required to be «attachment». That is, in short, we find all the files (attachment) which we downloaded for our 10 entries.
Again we form a list of ID: the first 10 ID entries and add the ID of files (attachments). Attachments as ordinary records are stored in one table – wp_posts.
Now we use the function update_meta_cache:
update_meta_cache:
$ar_all_id – here are the original recordings and attachments
So everything just gets in the cache and subsequent calls get_post_meta will derive value from the cache. The rest is a matter of technique – the data must be carefully arranged, not mixing anything up. All meta fields are added to the $post->meta array, and files into an $post->files array and files are immediately sorted by number order (when downloading it, you can specify the sort order).
In addition, for each file, if it is an image, the full path to the thumbnails is calculated: small (thumbnail), average (medium) and the complete picture (full).
To see the whole picture, I really recommend to add this printout anywhere in the body of the main loop:
Now, to get the value of meta fields, you no longer need to call the get_post_meta ($post->ID, ‘metaName’, true);
All fields will be located in an associative $post->meta array, that is, for metaName you need to use $post->meta['metaName'].
Check if a field metaName and print it.
All files attached to records are in the $post->files array.
For example, to check whether there is at least one image uploaded for the current record, and if it is uploaded, to withdraw its small image, but if not then put up the placeholder.
if($post->files[0]):?>
That’s just two extra SQL that immediately solved a bunch of problems.
The function ‘function all_inclusive ($posts, $forcibly = 0)’ can be used not as a plugin, simply add it to your current theme in file function.php and then use the automatic invocation:
$forcibly if not specified the function will only be for the main loop
if (have_posts ()) while (have_posts ())
then the filter removes himself to avoid a restart for minor SQL query.
Discount all inclusive vacations and honeymoons: Caribbean, Jamaica, Mexico, Excellence Resorts, Palace Resorts, Couples, Hedonism and Grand Lido. Compare all inclusive holidays from a range of holiday providers. All inclusive holidays from First Choice. Alihoco offers cheap all inclusive holidays and access to over 50000 all inclusive hotels. Смотри All inclusive или Все включено онлайн бесплатно и без регистрации. Great value all inclusive holidays to a variety of worldwide destinations. All inclusive holidays with the experts to Egypt, Caribbean, Spain and lots more with all inclusive holidays great advice and user reviews.
,
- специализированная доска объявлений по недвижимости на стоимость сборки $300 с установкой. городская доска объявлений, основные разделы: недвижимость, транспорт, услуги, работа, куплю-продам. Стоимость сборки $300 с установкой. - разработка, поддержка.