This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Update a post programmatically | |
$my_post_id = 15 | |
$update_post = array( | |
'ID' => $my_post_id, | |
'post_title' => 'My new post title', | |
'post_content' => 'Overwrite post content', | |
'post_status' => 'public' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Insert custom post programmatically | |
$new_post = array( | |
'post_title' => 'My new example post', | |
'post_content' => 'My new content!', | |
'post_status' => 'public', | |
'post_type' => 'my_post_type' | |
); | |
$post_id = wp_insert_post( $new_post ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Insert post programmatically | |
$new_post = array( | |
'post_title' => 'My new post', | |
'post_content' => 'Content to insert.', | |
'post_status' => 'publish' | |
); | |
$post_id = wp_insert_post( $new_post ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the ID of the featured image | |
echo get_the_post_thumbnail( get_the_ID(), 'large' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the current post or page's slug | |
$slug = get_post_field( 'post_name', get_post() ); | |
echo $slug; | |
// Get slug for a post or page by ID | |
$post_id = 1; | |
echo get_post_field( 'post_name', $post_id ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $post; | |
$slug = $post->post_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$meta_query_args = array( | |
'meta_query' => array( | |
array( | |
'key' => 'my_date_field', | |
'value' => array( strtotime('2022-01-01'), strtotime('2022-12-31') ), | |
'type' => 'numeric', | |
'compare' => 'BETWEEN' | |
) | |
) |