Coding : How to change post_format value
-
Hi,
I’m trying to figure out what I’m doing wrong in the attached coding example.
I can successfully post to wordpress, but I can’t figure out how to change the post_format value to “link” successfully. No matter what I have tried, the post_format value is set to ‘standard’. I need it set to ‘link’ and also be able to designate a URL. I’ve spent lots of time looking at posts on the internet with no luck. I’m missing ‘something’.
The php file for testing resides in the root directory of my wordpress installation.
<?php //figure out how to add a post with link format and URL error_reporting(-1); $location = $_SERVER['DOCUMENT_ROOT']; echo $location; //exit; include ($location . '/wp-config.php'); include ($location . '/wp-load.php'); include ($location . '/wp-includes/pluggable.php'); //include_once($location.'/wp-includes/post-formats.php'); require($location . '/wp-blog-header.php'); // Create post object $my_post = array(); $my_post['post_title'] = 'Title of this Post'; $my_post['post_content'] = 'Some Content to Add'; $my_post['post_status'] = 'publish'; $my_post['post_type']= 'post'; //post_category is correct here $my_post['post_category'] = array(34); //post_format always goes to 'standard' //tried array(2) also with no luck $my_post['post_format']='link'; //very array print_r ($my_post); //all the below commented options were tried with no success. //set_post_format('', 'link' ); //sets the given post to the 'link' format //set_post_format($mypost->'ID', 'link' ); //sets the given post to the 'link' format //$my_post['post_link_url'] = "https://www.SomeTestUrl.com"; //$my_post['post_link'] = "https://www.SomeTestUrl.net"; // Insert the post into the database if( null == get_page_by_title( $my_post['post_title'] ) ) { wp_insert_post( $my_post ); } //Post is successfully added but can't change post_format value to 'link' ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Coding : How to change post_format value’ is closed to new replies.