Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / upload-and-parse-csv-file.php
Created April 14, 2017 05:07
PHP: Upload and parse CSV file
<?php
if(isset($_POST['submit'])) {
$fh = fopen($_FILES['file']['tmp_name'], 'r+');
$lines = array();
while( ($row = fgetcsv($fh, 8192)) !== FALSE ) {
$lines[] = $row;
}
var_dump($lines);
}
?>
@dgoze
dgoze / functions.php
Created April 14, 2017 05:18 — forked from ville6000/functions.php
Change post per page
<?php
function change_posts_per_page( $query ) {
if ( is_main_query() && is_archive() ) {
$query->set( 'posts_per_page', -1 );
}
}
add_action( 'pre_get_posts', 'change_posts_per_page' );
@dgoze
dgoze / functions.php
Created April 14, 2017 05:20 — forked from ville6000/functions.php
Exclude page from Wordpress search
function your_theme_exclude_pages_from_search( $query ) {
$query->set( 'post__not_in', PAGE_ID_HERE );
return $query;
}
add_filter( 'pre_get_posts', 'your_theme_exclude_pages_from_search' );
$post_id = 1; //Post ID
$post_taxonomies = get_field('assigned-taxonomies', $post_id);
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'your-taxonomy',
'field' => 'term_id',
'terms' => $post_taxonomies
@dgoze
dgoze / acf_map_address.php
Created April 14, 2017 05:22 — forked from leanda/acf_map_address.php
Explode address information ACF Google Map
<?php
$location = get_field('your_location');
if( !empty($location) ):
?>
<?php $location = explode( "," , $location['address']);
echo $location[0].', '; //street number
echo $location[1].','.$location[2]; //city, state + zip
// print_r($location);
@dgoze
dgoze / gist:42c83af198a56c0064cd842d3e6a2e7d
Created April 24, 2017 03:17
WordPress ACF Multisite location rule
<?php
/**
*
* Adds location rule to target specific sites in a WordPress Multisite environment
* http://www.advancedcustomfields.com/resources/custom-location-rules/
*
*/
function acf_location_rule_type_blog( $choices ) {
@dgoze
dgoze / acf-pro-license-update.php
Created April 24, 2017 03:19 — forked from ngearing/acf-pro-license-update.php
ACF Pro License update ManageWP
<?php
$pro_license = maybe_unserialize(base64_decode(get_option('acf_pro_license')));
if (!$pro_license || $pro_license['url'] != home_url()) {
$save = array(
'key' => 'license_here',
'url' => home_url()
);
$save = maybe_serialize(base64_encode($save));
@dgoze
dgoze / gform_acf.php
Created April 24, 2017 03:21 — forked from kristarella/gform_acf.php
Convert Gravity Form multiselects to ACF format
<?php
add_action('gform_after_submission_14', 'reformat_multiselect', 10, 2);
function reformat_multiselect($entry, $form) {
$post_id = $entry['post_id'];
$selects = array(
'custom_field1' => 'ACF_field_key',
'custom_field2' => 'ACF_field_key',
'custom_field3' => 'ACF_field_key'
@dgoze
dgoze / functions.php
Created May 19, 2017 04:00 — forked from yratof/functions.php
Advanced Custom Fields - Update Image / File with Gravity Forms
// Front Raw
$gravity_form_id = 6; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter("gform_after_submission_{$gravity_form_id}", 'eve_set_front_raw_image_field', 10, 2);
function eve_set_front_raw_image_field($entry, $form){
$gf_images_field_id = 50; // the upload field id
$acf_field_id = 'field_54ca50b09afe2'; // the acf front raw field id
// get post
if (isset($entry['post_id'])) {
$post = get_post($entry['post_id']);
@dgoze
dgoze / custom-post-taxonomy-permalinks.php
Created September 5, 2017 02:40 — forked from kasparsd/custom-post-taxonomy-permalinks.php
Create permalink structure URLs for custom post types that include all parent terms from a custom taxonomy
<?php
/*
Term Archive Pages:
- http://example.com/recipes/dinner/
- http://example.com/recipes/breakfast,brunch/
Single Recipe Pages:
- http://example.com/recipes/dinner/soup-title/