Skip to content

Instantly share code, notes, and snippets.

View prasadnevase's full-sized avatar

Prasad prasadnevase

View GitHub Profile
@prasadnevase
prasadnevase / gist:1ae15b0150da324231be79c154cf5019
Created March 16, 2021 18:26
WP CLI command to update post category of all posts having specific old category
wp post update --post_category=sample $(wp post list --cat=1 --format=ids)
@prasadnevase
prasadnevase / functions.php
Created February 16, 2021 08:06
WordPress - render LIVE site media on local setup
<?php
// Replace the https://livesite.com/ with actual URL
add_filter( 'wp_get_attachment_url', function( $url, $attachment_id ) {
return str_replace( home_url(), 'https://livesite.com/', $url );
}, 99, 2 );
// Replace the https://livesite.com/ with actual URL
add_filter( 'wp_get_attachment_image_src', function( $image, $attachment_id ) {
$image[0] = str_replace( home_url(), 'https://livesite.com/', $image[0] );
@prasadnevase
prasadnevase / wp-cli-update-featured-image-to-all-posts
Created May 6, 2020 13:19
Bulk update same featured image to all posts
@prasadnevase
prasadnevase / wp-cli-delete-products.txt
Created March 27, 2018 17:22
Delete all products from trash using wp cli
wp post delete $(wp post list --post_type='product' --post_status=trash --format=ids)
@prasadnevase
prasadnevase / wc-attr-ordered-list.php
Last active August 28, 2016 17:55
WooCommerce Shortcode to get Ordered List of Attributes
<?php
function get_ordered_list_of_attributes(){
global $product;
$formatted_attributes = array();
$attributes = $product->get_attributes();
foreach($attributes as $attr=>$attr_deets){
@prasadnevase
prasadnevase / woo-custom-checkout-fields-with-email.php
Last active April 23, 2016 14:53
WooCommerce Custom Checkout Fields with Fields Added in Order Email
<?php
/* Add the field to the checkout */
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
woocommerce_form_field( 'p_trade', array(
@prasadnevase
prasadnevase / bacs-account-shortcode.php
Last active July 10, 2020 11:29
WooCommerce - Shortcode to list BACS accounts on checkout page
<?php
/* Usage: Put [bacs_account_details] shortcode in "WooCommerce > Settings > Checkout > BACS > Description field" */
/* This function outputs the BACS account details */
function list_bacs_accounts() {
$accounts = get_option( 'woocommerce_bacs_accounts');
if ( $accounts ) {
$list_accounts = '<table>
<thead>
@prasadnevase
prasadnevase / Show users own media only
Last active October 9, 2015 04:47
WordPress Code to show media of logged in user in the media library. He won't be able to access media from other users.
add_action( 'pre_get_posts', 'users_own_attachments');
function users_own_attachments( $wp_query_obj )
{
global $current_user, $pagenow;
if ( $pagenow == 'upload.php' || ( $pagenow == 'admin-ajax.php' && !empty( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'query-attachments' ) ) {
$wp_query_obj->set( 'author', $current_user->ID );
}
}
<?php
$term = get_query_var( 'category_name' );
echo "<h2>" . $term . "</h2>";
query_posts(array( 'post_type'=>'post', 'category' => $term, 'posts_per_page' => -1 ));
if ( have_posts() ) : while ( have_posts() ) : the_post();
echo "<h2>" . the_title() . "</h2>";
echo "<section>". the_content(). "</section>";
print apply_filters( 'taxonomy-images-list-the-terms', '' );
endwhile; else:
echo "<h3> Sorry, no matched your criteria</h3>";