Skip to content

Instantly share code, notes, and snippets.

View SamuelHadsall's full-sized avatar

Samuel Hadsall SamuelHadsall

View GitHub Profile
@SamuelHadsall
SamuelHadsall / list-field
Created September 28, 2024 19:17
Populate list field with php and acf repeater
function populate_company_list_field_with_array($value) {
if (current_user_can('employer_admin')) {
// Get the current user's company ID
$company_id = get_user_meta(get_current_user_id(), 'company_id', true);
$list_field_values = array();
// Get the ACF repeater field data
$business_locations = get_field('business_locations', $company_id); // Replace with your ACF repeater field name
// Check if repeater field has data
@SamuelHadsall
SamuelHadsall / Permilinks and rewrites
Created May 1, 2024 19:37
Post type and redirects
@SamuelHadsall
SamuelHadsall / Data
Last active May 1, 2024 16:10
Working with wpGrapghql
{
"data": {
"marketByPath": {
"title": null,
"databaseId": 25250,
"link": "https://unitedvanlines-prod.me/movers/oh/columbus/",
"uri": "https://unitedvanlines-prod.me/movers/oh/columbus/",
"markets": {
"marketName": null
},
["agent"]=> string(37) "kirkwood-a-mrazek-moving-systems-u550" ["post_type"]=> string(5) "agent" ["name"]=> string(37) "kirkwood-a-mrazek-moving-systems-u550"
add_rewrite_rule(
'^movers/([^/-]+)/([^/-]+)/?$',
'index.php?post_type=agent&agent_actual_city=$matches[1]&name=$matches[2]',
'top'
);
if (is_singular('agent')) {
// Get the post ID
class ACF_CSV_Importer {
private $post_type;
private $csv_file_path;
public function __construct($csv_file_path, $postType) {
$this->csv_file_path = $csv_file_path;
$this->postType = $postType;
}
public function import_from_csv() {
@SamuelHadsall
SamuelHadsall / acf-update-via-json.php
Created March 5, 2024 16:59 — forked from jessepearson/acf-update-via-json.php
Automatically update Advanced Custom Fields field groups via JSON
<?php
/**
* Function that will automatically update ACF field groups via JSON file update.
*
* @link http://www.advancedcustomfields.com/resources/synchronized-json/
*/
function jp_sync_acf_fields() {
// vars
@SamuelHadsall
SamuelHadsall / README.md
Created August 17, 2023 20:40 — forked from theJasonJones/README.md
Auto Populate Wordpress ACF Repeater values

Add default values to ACF Repeater Fields

I came across this solution when I had about a ton of posts (200+) with values in various PDFs. I didn't want to have to spend time filling out the same values over and over again.

Walkthrough

This case is pretty straight forward; I have one repeater field field_123a56b7cb890 that has a text fields inside it (field_588a24c3cb782). I haven't tried any other types like post objects or radio buttons, but I'm sure it can be done.

Step 1. Hook into acf/load_value on your repeater field. You can use type/key/name as desired here.

@SamuelHadsall
SamuelHadsall / acf_field_group
Last active June 6, 2023 17:47
Imports csv and maps to acf fields
<?php
if (!function_exists('acf_add_local_field_group')) {
return;
}
acf_add_local_field_group([
'key' => 'demographics_5b73377adf04f',
'title' => 'Demographics',
'fields' => [
[
@SamuelHadsall
SamuelHadsall / post_type_link_rewrites
Last active February 18, 2021 22:50
Taxonomy and Post Type and setting Post type link and rewrites
<?php
function bctv_register_episode_post_type_taxes() {
/**
* Taxonomy: Series Typess.
*/
$labels = array(
"name" => __( "Series Types", "bctv-post-type-ui" ),
"singular_name" => __( "Series Types", "bctv-post-type-ui" ),
@SamuelHadsall
SamuelHadsall / Checkout Quantity
Created July 30, 2020 16:49
Updates Quantity on Checkout Form
function add_quantity( $product_title, $cart_item, $cart_item_key ) {
/* Checkout page check */
if ( is_checkout() ) {
/* Get Cart of the user */
$cart = WC()->cart->get_cart();
foreach ( $cart as $cart_key => $cart_value ){
if ( $cart_key == $cart_item_key ){
$product_id = $cart_item['product_id'];
$_product = $cart_item['data'] ;