post_content with line breaks

I believe this should work: $getPost = get_the_content(); $postwithbreaks = wpautop( $getPost, true/false ); echo $postwithbreaks; The second argument in wpautop can be up to you whether it’s true of false, see the link below. It is described as follows: (bool) (Optional) If set, this will convert all remaining line breaks after paragraphing. Line breaks … Read more

WordPress AJAX with Axios

you can use FormData an example: let form_data = new FormData; form_data.append(‘action’, ‘myAction’); form_data.append(‘first_name’, ‘my first name’); form_data.append(‘phone’, ‘my phone’); axios.post(myVars.ajax_url, form_data).then(function(response){ console.log(response.data); })

Changing the post date and time with function

Call wp_update_post() with a special value for ‘post_date’ and ‘post_date_gmt’: $time = current_time(‘mysql’); wp_update_post( array ( ‘ID’ => 123, // ID of the post to update ‘post_date’ => $time, ‘post_date_gmt’ => get_gmt_from_date( $time ) ) );

How to show related posts by category

The question has already been asked and the answer has been posted too, How to display related posts from same category? Add this code inside your single.php after a loop wherever you want to show related post, <?php $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID) ) ); if( $related … Read more

WooCommerce store with ~30,000 products [closed]

I hate to mention this on WordPress.Stackexchange, but I would go with using Magento in place of WordPress. I love WordPress and use it on almost every website that I build, but it was not specifically made for e-commerce. Magento handles just about everything better in regards to e-commerce. I only tend to use WordPress … Read more

Display posts of the last 7 days

In addition to birgire’s solution, as of WordPress 3.7, you can use Date parameters. Your arguments would look like this to filter posts from the last 7 days: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // Using the date_query to filter posts from last week ‘date_query’ => … Read more

How to rename default posts-type Posts

I used the following script to rename the default post type: function change_post_menu_label() { global $menu, $submenu; $menu[5][0] = ‘Portfolio’; $submenu[‘edit.php’][5][0] = ‘Portfolio’; $submenu[‘edit.php’][10][0] = ‘New Portfolio’; $submenu[‘edit.php’][16][0] = ‘Portfolio Tags’; echo ”; } add_action( ‘admin_menu’, ‘change_post_menu_label’ ); function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types[‘post’]->labels; $labels->name=”Portfolio”; $labels->singular_name=”Portfolio”; $labels->add_new = ‘New Portfolio’; $labels->add_new_item = ‘New … Read more

How can I de-register ALL styles all at once? And same with Javascript?

I hope you know what you are doing. You can use the wp_print_styles and wp_print_scripts action hooks and then get the global $wp_styles and $wp_scripts object variables in their respective hooks. The “registered” attribute lists registered scripts and the “queue” attribute lists enqueued scripts on both of the above objects. An example code to empty … Read more