Articles of array

Save an array from drop-down in custom meta box

I have successfully pulled a custom post type through into a drop-down that is in a custom meta box. However, when displaying it on the front end I would like to also provide a link to the actual post, not just the name of the post. So I am guessing I need to save this […]

Minimize database queries to user tables?

I’m trying to come up with a strategic way to collect large amounts of usermeta data (and output to the screen) while keeping database queries low. Some pages, like the home page, single pages, and category pages, load up in less than half a second with 40-60 queries. Other pages that contain large amounts of […]

use get_posts to get custom field data, but in one array

I’ve run a get_posts query in WordPress and need to pull a pair of custom fields and get all of them into one array. The get_posts query provides an array of posts, but when I use foreach to access the custom fields, I end up with separate arrays for each result. The Query $c_query = […]

how to store arrays into a database

I’m trying the store multiple rows into a database. The number of fields will change. Below is the way that I use to store just one row. <?php if(isset($_POST[‘save’])){ $wpdb->insert(‘wp_table_name’, array( ‘field_a’ => $_POST[‘field_a’], ‘field_b’ => $_POST[‘field_b’], ‘field_c’ => $_POST[‘field_c’], ‘field_d’ => $_POST[‘field_d’] ), array( ‘%s’, ‘%s’, ‘%s’, ‘%s’ ) ); } ?> <form> <input […]

Admin Options page. Save as Array

I’m not great with PHP. I’ve just created a WordPress admin options page and it works OK: // Admin Menu add_action(‘admin_menu’, ‘my_cool_plugin_create_menu’); function my_cool_plugin_create_menu() { $parent_slug = ‘test-slug’; $capability = ‘administrator’; // sub menus add_submenu_page( $parent_slug, ‘Test’, ‘Test’, $capability, ‘test’, ‘hp_settings_page’); //call register settings function add_action( ‘admin_init’, ‘cm_register_settings’ ); } function cm_register_settings() { // title […]

get_post_type() in in_array doesn't work for some reason

I am trying to create some function for metaboxes and some reason i can’t get get_post_type to work in in_array. Everything else seems to work in testing but in_array nope. This is the function that i have $metabox = array( ‘metabox_one’ => array( ‘title’ => ‘First’, ‘screen’ => array( ‘post’ ) ), ‘metabox_two’ => array( […]

Error in WP_update_post

i make php file outside from wordpress folder to edit wordpress post and i get error when i use this code. wp_update_post <?php include ‘/go1/wp-includes/post.php’;?> <?php // Update post 1 hello word $my_post = array( ‘ID’ => 1, ‘post_title’ => ‘This is the updated post title.’, ‘post_content’ => ‘This is the updated content.’, ); // […]

Saving an array in a single custom field

I have the following array that I want to store in a single custom field. array(“Accounting”=>”Peter”, “Finance”=>”Ben”, “Marketing”=>”Joe”); I want to store it by typing it in a custom field in wp-admin. Then I want to retrieve this custom field as an array in a page, with something like $pos = get_post_meta($post_id, ‘pos ‘, true); […]

Parsing php string in jquery

I am sending php array using serialise but the response is different. Here is my attempt $array = serialize($out); var_dump(serialize($array)); //string(58) “s:50:”a:2:{s:9:”sidebar-1″;i:5;s:12:”footer-insta”;i:2;}”;” The way I am sending this value, echo ‘<div data-ad = ‘.$array.’ class=”ash_loadmore”><span>LOAD MORE</span></div>’; As I am sending the serialised value using ajax, the value that ajax response give me, string(54) “a:2:{s:9:\”sidebar-1\”;i:5;s:12:\”footer-insta\”;i:2;}” I […]

update_post_meta from data in multidimensional array created from a form

So, I have a few form fields like so: <input name=’mainStageSatOrder[theband][theid]’ type=’hidden’ class=’band-id’ value=” />”; <input name=’mainStageSatOrder[theband][theorder]’ type=’hidden’ class=’band-order’ value=” />”; As you can see, these form fields (of which there are more, these are just examples of both types) create a multi-dimensional array like so (I hope, please correct me if I’m wrong): Array […]