Can’t get wp_insert_post to work

That is because you’re trying to define a property that is already defined, query a table with a wrong name, loop through an integer while you can use get_results instead of query method of $wpdb … I edited the code, hope it will help with your post duplication process: defined( ‘WP_USE_THEMES’ ) || define( ‘WP_USE_THEMES’, … Read more

Echo a hierarchical list of post data from custom fields

A little example, based on get_posts and get_post_meta. $locations = get_posts( array(‘post_type’ => ‘locations’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’ ); echo ‘<ul>’; foreach ($locations as $location) { $location_city = get_post_meta($location->ID, ‘city’, true); $location_state = get_post_meta($location->ID, ‘state’, true); $location_address = get_post_meta($location->ID, ‘address’, true); echo ‘<li>’ . $location_city; echo ‘<li>’ . $location_state . ‘</li>’; echo ‘<li>’ … Read more

$wpdb select query by month, post type, and taxonomy term

You’ve not joined the wp_terms or $wpdb->terms table where WordPress stores the term names. So here is the updated code- $post_type_query = ” AND post_type=”” . $selected_post_type . “””; $posts_per_month = $wpdb->get_results( “SELECT *, DATE_FORMAT(post_date, ‘%Y-%m’) AS month, COUNT(ID) AS count FROM {$wpdb->posts} AS wposts LEFT JOIN {$wpdb->postmeta} AS wpostmeta ON (wposts.ID = wpostmeta.post_id) LEFT … Read more

How to get an array of user roles with or without a specific capability?

Try with this: function get_roles_that_cant($capability) { global $wp_roles; if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $available_roles_names = $wp_roles->get_names();//we get all roles names $available_roles_capable = array(); foreach ($available_roles_names as $role_key => $role_name) { //we iterate all the names $role_object = get_role( $role_key );//we get the Role Object $array_of_capabilities = $role_object->capabilities;//we get the array … Read more

how to delete 30 day old data using PHP [closed]

You’re adding an extra wp_ prefix to your table and your using a timestamp instead of a MYSQL datetime. Below is how WP suggests you use $wpdb->query to delete rows, taken from the codex. EDITED global $wpdb; $wpdb->query( “DELETE FROM ” . $wpdb->prefix . “userinfo WHERE timeall < DATE_SUB(CURDATE(),INTERVAL 30 DAY)” ); $wpdb->prefix adds the … Read more

Updating a checkbox value to database for specific row in table

Rough answer to get you started. Inside the loop, use the row’s record number (a field called ‘IDnumber’, unique, auto) to help name the of a . The hidden <input> should have an id of something like <input hidden name=”idnumber” value=”<?php echo $row[idnumber];?>”> which will cause the vaue of that input field to be the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)