ต้องการ list title พร้อม link ของ post ออกมา
xxx.php อัพไว้ที่ root เรียกใช้งาน พิมพ์ url ให้ domain.com/xxx.php
<?php
require('wp-load.php');
?>
<ul>
<?php
$args = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
โพสต์ขึ้นไป wordpress ก็ทำแบบนี้
<?php
require('wp-load.php');
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( $_POST['post_title'] ),
'post_content' => $_POST['post_content'],
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 )
);
// Insert the post into the database
wp_insert_post( $my_post );
?>
ตัวอย่างการใช้งาน
<?php
require('wp-load.php');
// Gather post data.
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post vir9.com.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 )
);
// Insert the post into the database.
wp_insert_post( $my_post );
?>+https://developer.wordpress.org/reference/functions/wp_insert_post/