PHP code example of radishlab / myc-getter
1. Go to this page and download the library: Download radishlab/myc-getter library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
radishlab / myc-getter example snippets
$posts = [];
foreach ($query->posts as $post) {
$genresObjects = get_the_terms($post, 'genre');
$genres = [];
if (is_array($genresObjects)) {
foreach ($genresObjects as $genre) {
$genres[] = [
'name' => esc_html($genre->name),
'url' => esc_url(get_term_link($genre)),
];
}
}
$posts[] = [
'title' => esc_html($post->post_title),
'url' => esc_url(get_the_permalink($post)),
'image' => get_the_post_thumbnail($post, 'large'),
'author' => absint(get_field('author', $post)),
'genres' => $genres,
];
}
$args = [
'acf' => ['author' => 'string'],
'taxonomies' => ['genre' => 'link'],
];
$getter = new MycGetter($args);
$posts = [];
foreach ($query->posts as $post) {
$posts[] = $getter->escapedContent($post);
}
use RadishLab\MycGetter\MycGetter;
class MyClass {
public function MyMethod()
{
$getter = new MycGetter();
}
}
[
'fields' => ['title', 'url', 'image'],
'image_size' => 'large',
'image_type' => 'html',
'acf' => false,
'taxonomies' => false,
];
$args = [
'fields' => ['title'],
];
$getter = new MycGetter($args);
// The arguments used by the class will be:
[
'fields' => ['title'],
'image_size' => 'large',
'image_type' => 'html',
'acf' => false,
'taxonomies' => false,
];
add_filter('myc_getter_presets', function ($presets, $context) {
$presets['new_preset'] = [
'fields' => ['title'],
'image_size' => 'medium',
];
return $presets;
}, 10, 2);
$getter = new MycGetter('new_preset');
'acf' => [
'cards' => ['headline' => 'string', 'button' => 'link', 'text' => 'string']
],