Inserting choice in database table

The main issue with your code is that the form submission will always have the same value. This could be seen by debugging $_POST where you check if $_POST[‘submit’] was set. I set up a custom database table and added some dummy data. I think this more or less mirrors your setup. Here is the … Read more

Why Can’t PHPUnit UnitTest My WordPress Website

Unit tests for WordPress are a tricky thing. If you need to test the code with a live database, etc. I would suggest using the official WordPress test suite. I’ve gotten unit tests running for a plugin using that method before, but it wasn’t pretty, and was fairly unreliable. If you need to do it … Read more

Create WordPress pages with PHP

You can programmatically create posts and pages using wp_insert_post or insert content using WXR files via WordPress’s import feature. To use wp_insert_post see the documentation here: http://codex.wordpress.org/Function_Reference/wp_insert_post A simple example: $my_post = array( ‘post_title’ => ‘hello’, ‘post_content’ => ‘This is my post.’, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array(1), ‘post_type’ => ‘page’ ); … Read more

Metabox repeating fields – radio buttons not saving correctly

So I came back to this after practice and implemented some of the Alchemy setup, meaning all the inputs have names like name=”_movies[3]Metabox repeating fields – radio buttons not saving correctly” where 3 is the iteration we’re on in the loop. Create the Metabox // metaboxes should be registered on the add_meta_boxes hook add_action(‘add_meta_boxes’, ‘add_meta_boxes’ … Read more

How to create custom php script page

If you want to add custom page in WordPress, you need to add your custom PHP file into currently activated theme ( /wp-content/themes/ ) folder. Suppose you have child-theme. Put the file to child-theme folder. Then goto page section, Click Add New. In Page Attributes, Choose Template as your PHP File. Open the Page.php file, … Read more

How to check if new posts have been published since page load?

Determining the current time There’s the current_time() function in core that allows to pass three different values as first argument and gmt (the offset) as second argument. About the 1st: mysql -> gmdate( ‘Y-m-d H:i:s’ ), human readable e.g 2004/07/8 13:35:19 timestamp -> time(), the UNIX timestamp for e.g. 1335939007 A custom argument that is … Read more