Skip to content

Instantly share code, notes, and snippets.

View BenBroide's full-sized avatar

Ben Broide BenBroide

  • New York
View GitHub Profile
<?php
//----------------------------
// Old way of getting post and custom fields - Get fields inside the loop with get_post_meta() that has 2-3 parameters
//----------------------------
$the_query = new WP_Query( $args );
// Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
function get_post_metas( $post_id , $fields_array , $single ){
$fields_array_data = array();
if( is_array( $fields_array )){
foreach( $fields_array as $key => $value){
$fields_array_data[] = get_post_meta( $post_id, $value , $single );
}
}
if( !is_array( $fields_array )){
$fields_array_data[] = get_post_meta( $post_id, $fields_array , $single );
}
@BenBroide
BenBroide / woocomerce-link-to-add-product-qty.php
Last active August 19, 2016 14:49
WooCommerce - Link to add a qty of product
@BenBroide
BenBroide / Simple_custom_fields.php
Last active October 18, 2016 03:13
Simple custom fields snippet
<?php
function save_postdata( $post_id, $post, $update )
{
$meta_keys = array(
"location" => "text",
);
foreach( $meta_keys as $meta_key => $type )
{
if( isset( $_POST[ $meta_key ] ) )
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp core install --url=example.com --title=QuickWP --admin_user=admin --admin_password=123456 --admin_email=info@example.com
wp scaffold child-theme twentysixteen-child --parent_theme=twentysixteen
npm install -g bower
cd wp-content/themes/twentysixteen-child/
bower install --save datatables.net
bower install --save datatables.net-dt
wp core update
@BenBroide
BenBroide / QuickWpWooCommerece.bash
Last active April 21, 2017 13:53
QuickWpWooCommerece.bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp core install --url=example.com --title=QuickWP --admin_user=admin --admin_password=123456 --admin_email=info@example.com
wp scaffold child-theme twentysixteen-child --parent_theme=twentysixteen
wp plugin install woocommerce --activate
# Recives hostname : batz-bar-taxi-coupons-4241432
# returns: batz-bar-taxi-coupons
IFS='-' read -r -a host_name_array <<< "$(hostname)"
unset 'host_name_array[${#host_name_array[@]}-1]'
IFS=$'-'; echo "${host_name_array[*]}" ;
@BenBroide
BenBroide / simple-quick-wp-twentyseventeen.bash
Last active April 23, 2017 18:25
Cloud9 auto setup WordPress TwentySeventeen +Child theme activated with wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
siteurl=$(hostname)
siteurl="${siteurl%-*}"
echo $siteurl
echo "${siteurl%-*}"
wp core install --url=example.com --title=QuickWP --admin_user=admin --admin_password=123456 --admin_email=info@example.com
wp scaffold child-theme twentyseventeen-child --parent_theme=twentyseventeen
@BenBroide
BenBroide / setup-wp-twentyseventeen-child-plugins.sh
Last active October 10, 2017 13:12
Turn c9 WordPress workspace server "ON" and paste this bash code in the c9 ide terminal and click "enter"
#turn workspace server on ( "RUN" button), paste this into c9 terminal, and hit "enter"
SETUP_PATH="setup.sh"
cat >$SETUP_PATH <<'EOF'
#!/bin/bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp core install --url=https://$C9_HOSTNAME --title=QuickWP --admin_user=admin --admin_password=123456 --admin_email=$C9_EMAIL
wp option update my_option '{"site_url": "bar"}' --format=json
wp theme install twentyseventeen
@BenBroide
BenBroide / remote-url-file-to-wp-library.com
Last active March 29, 2018 02:43
Save remote file by URL to WordPress Media Library
$get = wp_remote_get( $fileurl );
$mirror = wp_upload_bits( basename( $fileurl ), '', wp_remote_retrieve_body( $get ) );
$attachment = [
'post_status' => 'inherit',
'post_mime_type' => $mirror['type'],
'parent_id' => $this_post_id,
'post_title' => $file_title
];
wp_insert_attachment( $attachment, $mirror['file'], $this_post_id );