How to make an activities stream mixing posts and comments?
I believe you’re looking for SQL UNION.
I believe you’re looking for SQL UNION.
Note, before going further: Take care about portability and security: function wpse50056_get_post_meta() { global $wpdb; $results = $wpdb->get_results( ” SELECT ID, post_date, post_title, post_content, meta_key, meta_value FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON ( $wpdb->posts.ID = {$wpdb->postmeta}.post_id ) ” ); foreach( $results as $result ) { printf( ‘<pre>%s</pre>’, htmlspecialchars( var_export( $result, true ) ) ); } … Read more
To answer the question directly, there is $wpdb->update but nothing that will strictly duplicate INSERT IGNORE that I know of. If $wpdb->update, does not work I am fairly sure that you will need to write your own query and use $wpdb->query and $wpdb->prepare.
Actually, the customary way to do this in WordPress would be to use <?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?> as per the codex: https://codex.wordpress.org/Function_Reference/update_post_meta. It yields shorter code, and the intent of the code is clearer.
The plugin probably (or: hopefully) used the $wpdb object, an instance of the wpdb-class, to add the custom table. If so (and only if so), then its author probably also uses $wpdb->insert() to add rows/ entries to the table. Taking a look at wpdb::insert(), and looking at its source, you will find out that this … Read more
OK, so here is how you should to this proper way… In your template file you put your form: <form id=”myForm” name=”myform” action=”<?php echo esc_attr( admin_url(‘admin-post.php’) ); ?>” method=”POST”> <input type=”hidden” name=”action” value=”save_my_custom_form” /> <select id=”brandSel” size=”1″> <option selected=”selected” value=””>– Select Brand –</option> <option>Abba</option> <option>AG Hair</option> </select> <input type=”submit” value=”submit” /> </form> And in functions.php … Read more
Great advice Rarst! The output of $wpdb->queries was exactly what it should be: “INSERT INTO `wp_featured_releases` (`fr_band`,`fr_album`,`fr_album_description`,`fr_image_id`,`fr_shop_url`,`fr_modified`) VALUES (”,”,”,’504′,”,’2011-01-14 10:49:58pm’)” 504 is the correct id for the image, but the value in the table is still 127. My latest thought is that my mysql skills have failed me. Images with an ID below 127 work … Read more
Nonce You are going to want to set a nonce hidden field or to the element so that you can verify the request. Take a look at the codex for examples. Setting the POST ID and Nonce You will need to add the id of the specific post to the delete button or to a … Read more
Use a custom view in the front-end: You can try to modify the SELECT queries in the front-end with the following (alpha) plugin: <?php /** * Plugin Name: wpdb – a custom SELECT view for the wp_posts table on the front-end * Version: alpha */ ! is_admin() && add_filter( ‘query’, function( $query ) { global … Read more
No, you do not want to swap out the tablename. If you do, the table name will be wrapped in quotes and it will trigger a SQL error. Try: $table = $wpdb->prefix . ‘members’; $qry = $wpdb->prepare(“SELECT * FROM %s”, $table); var_dump($qry); $qry = “SELECT * FROM $table”; var_dump($result); The first string is invalid SQL. … Read more