Skip to content

Instantly share code, notes, and snippets.

View SamuelHadsall's full-sized avatar

Samuel Hadsall SamuelHadsall

View GitHub Profile
@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'] ;
@SamuelHadsall
SamuelHadsall / DataFeed.php
Last active August 7, 2020 03:49
Generate XML with Custom Post Type
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://www.steadyrain.com
* @since 1.0.0
*
* @package The_Factory
* @subpackage The_Factory/admin