Custom_Fields seem to be broken
mmackenz opened this issue · 4 comments
Hi, I upgraded to the latest version and I can not get or set custom fields. I have read the post (post.toXmlRpcStruct()) and the custom_fields is always null.
Hi,
Thank you for reporting this. Can you quote your code so that we can
reproduce and fix?
On Jul 28, 2015 10:43 PM, "mmackenz" notifications@github.com wrote:
Hi, I upgraded to the latest version and I can not get or set custom
fields. I have read the post (post.toXmlRpcStruct()) and the custom_fields
is always null.—
Reply to this email directly or view it on GitHub
#51.
Sorry to lack so detail in my previous post:
Below is a quick demo class. Sorry I can't provide credentials to my site.
import java.util.List;
import net.bican.wordpress.CustomField;
import net.bican.wordpress.Post;
import net.bican.wordpress.Wordpress;
public class CfDemo {
public static void main(String[] args) {
try {
Wordpress wp;
wp = new Wordpress(username, password, xmlRpcUrl);
/*
* post id 28 has parent of 0, custom_fields of
* _yoast_wpseo_focuskw
* _yoast_wpseo_metadesc
* _yoast_wpseo_title
*/
Post post = wp.getPost(28);
List cfs = post.getCustomFields();
if(cfs == null) {
System.out.println("cfs is null");
}
// cfs is null and i don't see the custom_fields in the XmlRpc.
System.out.println(post.toXmlRpcStruct());
// also customFields:null
System.out.println(post);
} catch (Exception e) {
e.printStackTrace();
}
}
Wordpress wp;
private static final String username = "foo";
private static final String password = "bar";
private static final String xmlRpcUrl = "http://www.foobar.com/xmlrpc.php";
}
OK, I see the mistake: I should have used custom_fields, not customFields.
I just committed a fix and will release the changed library in a moment. Please use version 0.6.2. Now you can use it like this:
Post post = new Post();
post.setPost_content("test content");
post.setPost_title("test title");
post.setPost_excerpt("test excerpt");
List<CustomField> customFields = new ArrayList<>();
CustomField cf1 = new CustomField();
cf1.setKey("test key1");
cf1.setValue("test value1");
customFields.add(cf1);
CustomField cf2 = new CustomField();
cf2.setKey("test key");
cf2.setValue("test value2");
customFields.add(cf2);
post.setCustom_fields(customFields);
Integer postId = WP.newPost(post);
Works Great! Thank you so much!!