Publish pending article from front end with a button?

First create a function that will print the publish button : //function to print publish button function show_publish_button(){ Global $post; //only print fi admin if (current_user_can(‘manage_options’)){ echo ‘<form name=”front_end_publish” method=”POST” action=””> <input type=”hidden” name=”pid” id=”pid” value=”‘.$post->ID.'”> <input type=”hidden” name=”FE_PUBLISH” id=”FE_PUBLISH” value=”FE_PUBLISH”> <input type=”submit” name=”submit” id=”submit” value=”Publish”> </form>’; } } Next create a function to change … Read more

Post publish only hook?

The {$old_status}_to_{$new_status} and {$new_status}_{$post->post_type} hooks tend to generally solve the problem. To avoid running the code in case post status is changed to draft then published again (after already being published), implement a simple flag using the post_meta functionality. Note: the updated hook should be ‘draft_to_publish’ instead of ‘draft_to_published’ however, the code below is not … Read more

Querying post from a multisite network

You could use your list of blog ids in this way … $posts = array(); foreach ( $your_list_of_blog_ids as $blog_id ) { switch_to_blog( $blog_id ); $query = new WP_Query( array( ‘post_type’ => ‘any’, ‘posts_per_page’ => 10, ) ); while ( $query->have_posts() ) { $query->next_post(); $posts[] = $query->post; } restore_current_blog(); } Important are switch_to_blog and restore_current_blog. … Read more

Accessing the post content with WP_Query

First of all, don’t use and abuse the $wp_query global variable. This global should be reserved to the main query only. Use any other variable that will not create conflict. Secondly, don’t use the raw WP_Post properties. These are raw and unfiltered. WP_Query does set up postdata by default which make the use of the … Read more

How do I reorder (pop and push) items from WP_Query?

You could use the Metadata API to retrieve the rw_advertising_position metadata for each post, seperate the ads from the content, and then re-insert the ads at the proper locations: /** * Extracts from an array posts with positional metadata and re-inserts them at the proper * indices. See https://wordpress.stackexchange.com/questions/210493 **/ function wpse_210493_apply_advertising_position( &$posts, $return = … Read more

Restore contents of deleted user

None that don’t involve a backup. If you have a backup, you’ll have to do some work to restore only a certain user’s data without resetting everything to that point. I’d say import the backup into an empty database, then copy data over either with SQL (INSERT INTO wp_posts SELECT FROM otherdb.wp_posts WHERE post_author = … Read more

Pretty URL with add_query_var

add_rewrite_endpoint( ‘changelog’, EP_ROOT ); Will add the endpoint, changelog, which you can then check on template_redirect hook. On match the query variables ( $wp_query->query ) array should contain key changelog containing whatever comes after the / in value. So for URL example.com/product1/changelog/5 you would have a query variable named changelog with the value 5. If … Read more

Verify if tag is used on posts

Try using the has_tag() conditional template tag. e.g., to query for the tag “foobar”: <?php if ( has_tag( ‘foobar’ ) ) { // The current post has the tag “foobar”; // do something } else { // The current post DOES NOT have the tag “foobar”; // do something else } ?> If you’re inside … Read more

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