Tag Info

Hot answers tagged

2

<?php $args = array( 'posts_per_page' => -1, 'post_type' => 'event', 'meta_query' => array( array( 'key' => 'event_date_end_timestamp', 'value' => time(), 'type' => 'numeric', 'compare' => '<' ) ) ); $programs = new WP_Query($args); ?> ...


2

With everything moving towards OOP programming with classes and the use of objects increasing and favored above the use of arrays as such, I would definitely go with returning results as an object. This just makes everything easier for future use But at the end of the day, you should always use what you are comfortable with within a set scope while keeping ...


2

This error: Fatal error: Call to a member function insert() on a non-object Means that $wpdb isn't instantiated so you are running your code too early or out of WordPress context-- for example, in an exterior PHP file accessed directly, which is what I suspect (Poorly conceived AJAX request perhaps?). As mentioned, the code has more formats that data ...


1

Here is an example of performing a LIKE based query while escpaing the value parameter passed to the query: $results = $wpdb->get_results( $wpdb->prepare( "SELECT post_title, ID from $wpdb->posts WHERE post_title LIKE '%%%s%%'", $wpdb->esc_like("today's weather is nice") ) ); Update: Based on your edit, your query ...


1

The most likely cause is that the hook is probably running multiple times (e.g. once per meta field). You may need to qualify/filter your function like so… add_action( 'added_post_meta', function ( $mid, $object_id, $meta_key, $_meta_value) { global $wpdb; if ( $meta_key != 'data19' ) { return; } $table_name = $wpdb->prefix . 'postmeta'; ...


1

The function you are looking for is wp_update_post(). You would want to have your posts which you want to update, then set up a loop to update each one individually. // However you get your posts, ID's, etc. $posts = get_posts( array( 'post_type' => 'post' ) ); for ( $posts as $post ) { wp_update_post( array( 'ID' => $post->ID, 'post_parent' ...



Only top voted, non community-wiki answers of a minimum length are eligible