Alternative content when $var is falsy or null
$my_post_id,
)
);
########################## WP LOOOP
?>
/* -----------------------------------------------------------
QUERIES
-----------------------------------------------------------*/
6, 'post_type' => 'post');
$the_query = new WP_Query($args);
?>
if ($the_query->have_posts()) {
echo '';
while ($the_query->have_posts()) {
$the_query->the_post();
echo '- ' . get_the_title() . '
';
}
echo '
';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
// ##### Query 🡒 Get posts
$args = array(
'fields' => 'ids',
'post_type' => 'restaurants',
'posts_per_page' => -1
);
$posts = get_posts($args);
// ##### Query 🡒 Recent posts
$posts = wp_get_recent_posts([
'numberposts' => 4,
'post_status' => 'publish'
]);
// ##### Query 🡒 With Metaqueries
$args = array(
'post_type' => 'activities',
'post_status' => array('publish', 'future'),
'numberposts' => '3',
'meta_key' => 'date',
'orderby' => 'meta_value',
'order' => 'ASC',
// ######## Main
'meta_query' => array(
array(
'key' => 'date',
'value' => $today,
'compare' => '>='
)
)
);
$recent_activites = wp_get_recent_posts($args);
/* -----------------------------------------------------------
POST DATES
-----------------------------------------------------------*/
$post_date = date_i18n('j F Y', strtotime($post['post_date']));
/* -----------------------------------------------------------
URL
-----------------------------------------------------------*/
// ##### URL 🡒 Home Url
echo home_url('/admission/');
// ##### URL 🡒 Site Url
echo site_url('/admission/', 'https');
/* -----------------------------------------------------------
ENABLE SVG
-----------------------------------------------------------*/
/* */
function cc_mime_types($mimes)
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
/* -----------------------------------------------------------
INIT WIDGET
-----------------------------------------------------------*/
function tailwind_widgets_init()
{
register_sidebar(
array(
'name' => esc_html__('Discover_next', 'tailwind'),
'id' => 'discover_next',
'description' => esc_html__('Add widgets here.', 'tailwind'),
'before_widget' => '',
'before_title' => '',
)
);
}
/* -----------------------------------------------------------
POSTS
-----------------------------------------------------------*/
// Change Defaults Posts to "News" in menu bar
function cp_change_post_object()
{
$get_post_type = get_post_type_object('post');
$labels = $get_post_type->labels;
$labels->name = 'News';
$labels->singular_name = 'News';
$labels->add_new = 'Add News';
$labels->add_new_item = 'Add News';
$labels->edit_item = 'Edit News';
$labels->new_item = 'News';
$labels->view_item = 'View News';
$labels->search_items = 'Search News';
$labels->not_found = 'No News found';
$labels->not_found_in_trash = 'No News found in Trash';
$labels->all_items = 'All News';
$labels->menu_name = 'News';
$labels->name_admin_bar = 'News';
}
add_action('init', 'cp_change_post_object');
// Change Defaults Posts Icon in menu bar
function change_menu_icon()
{
// Access global variables.
global $menu;
foreach ($menu as $key => $val) {
if (__('News', 'plugin-name') == $val[0]) {
$menu[$key][6] = 'dashicons-welcome-widgets-menus';
}
}
}
add_action('admin_menu', 'change_menu_icon');
/* -----------------------------------------------------------
HIDE EDITOR ON SPECIFIC PAGE
-----------------------------------------------------------*/
function remove_editor_init()
{
if (isset($_GET['post'])) {
$id = $_GET['post'];
if ($id == 7) {
remove_post_type_support('page', 'editor');
}
}
}
add_action('init', 'remove_editor_init');
/* -----------------------------------------------------------
METABOX
-----------------------------------------------------------*/
// ###### REGISTER METABOX — SPECTACLES DATE DE CREA ######
function add_spectacles_metabox()
{
$screens = ['spectacles'];
foreach ($screens as $screen) {
add_meta_box(
'add_spectacles_creationdate_metabox', // Unique ID
'Création', // Box title
'spectacles_custom_metabox_html', // Content callback, must be of type callable
$screen, // Post type
'side' // 'side' pour le coté, 'normal' ou rien pour en side
);
}
}
add_action('add_meta_boxes', 'add_spectacles_metabox');
// ###### METABOX CONTENT DESCRIPTION — SPECTACLES CREATION ######
function spectacles_custom_metabox_html($post)
{
$date_creation = get_post_meta($post->ID, '_date_crea_field', true);
$encreation = get_post_meta($post->ID, '_encreation_field', true);
?>