wordpress functions dosn't work -
i have form grabs data users , save blog post.
the form action goes page:
wp-content/plugins/formplugin/savepost.php
but in page when try save post wp_insert_post($args)
, error happens:
"call undefined function wp_insert_post() in d:\easyphp-5.4.0rc4\www\wp2\wp-content\plugins\formplugin\savepost.php on line 18".
is there missing?
if(isset($_post['send'])){ $args=array( 'post_name' => $_post['postname'], 'post_title' => $_post['postname'], 'post_status' => 'publish', 'post_type' => 'post', 'post_excerpt' => $_post['postdesc'] ); wp_insert_post($args); }
include wordpress in external files:
it looks using external file outside scope of wordpress. if file in plugins folder, doesn't mean wordpress knows it.
you can include wordpress external file adding this:
<?php define( 'wp_use_themes', false ); require_once( '/path/to/your/wp-blog-header.php' );
at top of file. wp-blog-header.php
should located in wordpress root folder.
alternative:
but since using wordpress, why not construct pretty url , use hook intercept form posting, instead of pointing external file?
things consider:
you should consider using filter_input instead of $_post
.
i recommend using wordpress nonces.
it's rule validate , sanitize user input. here's starting point on matter.
Comments
Post a Comment