Tag Info

Hot answers tagged

11

First you have to get the images. How to get all images of a gallery is described here. WordPress uses two classes for unzipping files. The PHP bilt in ZipArchive() (usage see David Walsh). And PclZip, you can found this class in wp-admin/includes/class-pclzip.php. If you got problems with ZipArchive() try the PclZip class. Now you just to have to glue ...


10

If you're on a remote server, XMLRPC would be best, but requires login details If you're in a PHP script on the same server, wp-load.php would be best ( XMLRPC will involve a request of sorts ) If you're in a bash or CLI script, WP CLI would be best, e.g.: wp post create --post_type=page --post_status=publish --post_title='A future post' ...


9

This requires PHP 5.3+ (WP requires PHP 5.2.4+) add_filter('get_the_excerpt', 'end_with_sentence'); function end_with_sentence($excerpt) { $allowed_end = array('.', '!', '?', '...'); $exc = explode( ' ', $excerpt ); $found = false; $last = ''; while ( ! $found && ! empty($exc) ) { $last = array_pop($exc); $end = strrev( $last ); ...


9

A useful fast way is use javascript in combination with an ajax action that output the box. Create a small plugin. Create a folder inside plugins directory, naming it 'SubmitReviewConf'. In this folder create a php file named SubmitReviewConf.php. in this file, put this code: <?php /** * Plugin Name: Submit for Review Confirmation Message * Description: ...


7

Every post update in wordpress, is handled by the wp_update_post function. This function has some defaults, and for post_content_filtered the default value is '' (empty string). Once the default are merged to args passed to function via wp_parse_args it means that every time a post is updated and post_content_filtered is not explicitly passed, it is setted ...


7

Post list in admin (edit.php) use a normal WP_Query, just like frontend can be changed using pre_get_posts. add_action('pre_get_posts', 'reorder_my_cpt'); function reorder_my_cpt( $q ) { $s = get_current_screen(); // change 'book' with your real CPT name if ( is_admin() && $s->base === 'edit' && $s->post_type === 'book' ...


6

If I understand well, you need to retrieve all the posts having category 'y' and also meta key 'facebook_shares', after that, you need the position of a specific post. My proposal is: Create a class that extends WP_Query and filter the results for required category and meta field. This class should also filter the SQL query to set the meta value as a ...


5

The WordPress function get_the_modified_author() will give you the author who last edited the current post. But if you want to list all the users that have edit the current post, you could try: function get_the_modified_authors_wpse_99226(){ global $wpdb; $authors = array(); $results = $wpdb->get_results( $wpdb->prepare("SELECT ...


5

I use Advanced Custom Fields for lots of front end post editing with meta boxes. ACF allows you to build lots of advanced meta box fields and adds them automatically to the back end post panel. But there is a front end function as well. This method is completely free. The only way it costs anything is if you want to use any of their more complex field type ...


5

Here is a very rough block of code that should get you started. What it does is look for the most recent "future" or "publish" post and if that value is less than 1 hour different from the latest scheduled post, it schedules the current post to one hour plus the "most recent" time found. function force_time_between_posts_wpse_104677($data, $postarr) { ...


4

You might have a look at the WordPress Transient API. You should be able to store your shortcode output $total_network with set_transient( 'my_shortcode_cache', $total_network, WEEK_IN_SECONDS ); where WEEK_IN_SECONDS is a built in constant equal to 604800. You can then fetch it with: get_transient( 'my_shortcode_cache' ); If you need it to work ...


4

You can add code below to the beginning of loop.php add_action('pre_get_posts', 'wpse_change_post_order'); function wpse_change_post_order($query){ $query->set('order','ASC'); $query->set('orderby','date'); } the oldest posts will be in the home page.


4

publish_post will give you a second parameter if you ask for it. Notice the fourth parameter of the add_action call. That is your post object. function run_on_publish_wpse_100421($postid,$post) { if ('news' == $post->type) { // your code } } add_action('publish_post','run_on_publish_wpse_100421',1,2);


4

You can use a modified version of this answer by @s_ha_dum. Where instead of an option you can setup a user meta (even if meta query is slower than option query) add_action('save_post', 'user_last_update', 10, 2); function user_last_update($id, $p) { if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') ...


4

Archive Page An archive page is part of the WordPress Template Hierarchy, and is the template file WordPress uses to display the archive index list for a given post type. The custom post type archive template hierarchy is as follows: archive-{posttype}.php archive.php index.php WordPress uses the query parameters to output this page, and posts are ...


4

I found the following filter, here unlocking all protected meta data: add_filter( 'is_protected_meta', '__return_false' ); Or it can be fine tuned: add_filter( 'is_protected_meta', function( $protected, $meta_key, $meta_type ) { $allowed = array( '_edit_lock', '_test', '_wp_page_template' ); if( in_array( $meta_key, $allowed ) ) return ...


4

The problem with the code in your question is it always intercepts. You completely lose the ability to not publish, no drafts possible. Why this leads to untrashable post is something I didn't inspect further. Anyway this isn't what one wants. I'm glad the javascript solution is working for you, but personally I have two problems with it, first, you can ...


4

Preface Once post preview is frontend, the comment form depends on how theme handle it. I will assume in this answer that the comment form is shown using the standard comment_form() function. The previous assumption isn't enough, in fact comment_form is probably the function in WordPress core with more hooks. There is almost an hook for every line. So what ...


4

You need Post Status Transitions actions function notify_me_for_pending( $post ) { $user_info = get_userdata ($post->post_author); $strTo = array ('email@example.com'); $strSubject = 'Fstoppers: ' . $user_info->user_nicename . ' submitted a post'; $strMessage = '"' . $post->post_title . '" by ' . $user_info->user_nicename . ' was ...


4

I tried for a bit and could not get this to work perfectly, but it's close, it's hard to extend with the <form> for the popup styles being hardcoded, thought possible with more work. To get started you can: Enqueue the link popup javascript and styles, the main .js file is wp-includes/wplink.js. Depending on where you loading this you might need to ...


4

I suppose you're looking for something like this...? function delete_associated_media($id) { // check if page if ('page' !== get_post_type($id)) return; $media = get_children(array( 'post_parent' => $id, 'post_type' => 'attachment' )); if (empty($media)) return; foreach ($media as $file) { // pick what ...


4

How about this? It adapts an example on the get_posts() function reference page. function delete_post_media( $post_id ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'post_parent' => $post_id ) ); foreach ( $attachments as ...


4

On that page $post->ID returns the ID of first blog post for given page. That is how it works. $post is set to the first post in the Loop. On single posts and pages that is the same as the post or page. On archive pages it is the first post in the result set. And if you think about that, both are really the same thing. Single posts and pages only have ...


4

$wpdb->prepare() doesn't actually fully support sprintf() placeholders. From the Codex: The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d (integer) and %f (float) formats are supported. It's not entirely obvious from that but the argument swapping formats (e.g. %1$d) are not supported (in any case you have ...


4

Why don't you use WordPress get_posts? You can add the parameter orderby => 'title' as you want. $args = array( 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title' ); $posts = get_posts( $args ); print_r($posts); If you want the sql you can just add ORDER BY post_title: SELECT * FROM $wpdb->posts ...


4

If you want the meta box to appear below the content area, use the context parameter 'normal'. See Function Reference/add meta box - Parameters. Initially, your meta box should only go to the side bar if the context parameter is set to 'side'. As far as making it impossible for the user to drag it to the side, study the answer at "Block metabox - No ...


4

You can technically add a post column with SQL but I'd caution against it as backup scripts, exports etc. would likely ignore it. Instead, I would add the content as a post_meta, either using a Custom Field or through PHP with the update_post_meta() function. To fetch a post based on the meta simply use: $args = array( 'post_type' => ...


4

The following query retrieves the oldest post of a specified user/author: $user_id = 42; // or whatever it is $args = array( 'posts_per_page' => 1, 'post_status' => 'publish', 'author' => $user_id, 'orderby' => 'date', 'order' => 'ASC', ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { ...


4

You can use 'the_title' filter (Codex link) add_filter( 'the_title', 'lose_four_chars'); function lose_four_chars($title) { if ( is_single()) { return substr($title, 4); } else { return $title; } }


3

Alternatively to Kaiser's answer, when you register the post type, simply use the taxonomies attribute: register_post_type( 'my-cpt', array( ... 'taxonomies' => array( 'category' ), ... ) ); Details on register_post_type() can be found here in Codex.



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