how to bulk add one line in the first paragraph of all posts

I’d go for solution posted by @butlerblog – it’s a lot easier to manage and change in the future and it’s better WP practice. But… If you’re asking… Here are the ways you can do this: 1. WP way: function prepend_content_to_posts() { $to_prepend = ‘This will be prepended’; $posts = get_posts( array( ‘posts_per_page’ => -1 … Read more

transition_post_status hook doesn’t have any POST data when publish with Gutenberg [closed]

But you shouldn’t use $_POST inside that hook. transition_post_status fires when a post is transitioned from one status to another. It can be caused by anything (not only by sending POST request from editor). For example here’s the function that is responsible for publishing future posts: check_and_publish_future_post. It’s called only by cron, without sending any … Read more

Remove a shortcode from all WordPress posts

I love to use this tool, Search and Replace for WordPress Databases. It is basically a PHP script that is written for WordPress usage (but of course can be used with any database). When placed in the WordPress project, it automatically detects and loads the Database using data from wp-config.php file. It enables you to … Read more

Redirect to another page using contact form 7? [closed]

Redirect to another page using contact form 7? [closed]

How to setup a query to output posts by groups of five?

you can create a simple counter and condition: <?php $count = 0; ?> <?php if( $query->have_posts() ) : ?> <ul class=”posts”> <?php while ( $query->have_posts() ) : $query->the_post(); if ($count < 5){ ?> <li> <?php the_title(); ?> </li> <?php }else{ echo ‘</ul><ul class=”posts”>’; ?> <li> <?php the_title(); ?> </li> <?php $count = 0; } $count … Read more

Do action on publish or update?

Why don’t you wrap it in post save_post and post_publish hooks? You have examples here: http://codex.wordpress.org/Function_Reference/add_action How to do it: Add this to your functions.php file: function my_data_update () { $company = get_field(‘company_name’); $address = get_field(‘address’); $city = get_field(‘city’); $post_code = get_field(‘post_code’); //etc etc… } add_action(‘publish_post’, ‘my_data_update’); add_action(‘save_post’, ‘my_data_update’);

How to sort posts in a custom post type by title in ascending order by default?

You should use pre_get_posts: add_action(‘pre_get_posts’,’wpse56753_businesses_default_order’); function wpse56753_businesses_default_order( $query ){ if( ‘business’ == $query->get(‘post_type’) ){ if( $query->get(‘orderby’) == ” ) $query->set(‘orderby’,’title’); if( $query->get(‘order’) == ” ) $query->set(‘order’,’ASC’); } }