Skip to content

Instantly share code, notes, and snippets.

@mishterk
mishterk / example-table-definition-for-page-post-type.json
Created Feb 20, 2018
ACF Custom Database Tables plugin: Table definition JSON example for post type of 'page'
View example-table-definition-for-page-post-type.json
{
"name": "page_metadata",
"relationship": "page",
"columns": [
"show_page_banner",
"page_layout",
"read_time"
]
}
@mishterk
mishterk / example-table-definition-for-user-type.json
Created Feb 20, 2018
ACF Custom Database Tables plugin: Table definition JSON example for user type
View example-table-definition-for-user-type.json
{
"name": "user_metadata",
"relationship": "user",
"columns": [
"profession",
"age",
"sex",
"is_member",
"instagram_url"
]
@mishterk
mishterk / example-bypassing-core-tables.php
Last active Feb 20, 2018
ACF Custom Database Tables plugin: Bypassing core meta tables example.
View example-bypassing-core-tables.php
<?php
/*
* This will prevent data from being stored in WordPress' core meta tables where a custom database table has been set up instead.
* This will not affect meta data that does not have a custom database table – that meta data will be stored as usual.
*/
add_filter('acfcdt/settings/bypass_post_meta_table', '__return_true');
@mishterk
mishterk / example-table-definition-structure.json
Last active May 27, 2018
ACF Custom Database Tables plugin: Table definition JSON structure
View example-table-definition-structure.json
{
"name": "{custom_database_table_name}",
"relationship": "{post_type}",
"columns": [
"{acf_field_name_1}",
"{acf_field_name_1}",
"{acf_field_name_3}"
]
}
@mishterk
mishterk / 0-readme.md
Last active Apr 14, 2019
A basic, static view handler for WordPress
View 0-readme.md

Basic Usage

// set up
View::$view_dir = '/some/path';

// echos the view
View::render('relative/template', [
  'var1' => 'data',
 'var2' =&gt; 'more data'
View procedural-wp-rest-api-get-requests.php
<?php
/**
* Really simple GET request
*/
add_action( 'rest_api_init', function ( WP_REST_Server $wp_rest_server ) {
register_rest_route( '/custom-namespace/v1', '/no-param', [
'methods' => 'GET',
'callback' => function ( WP_REST_Request $request ) {
if ( $throw_error = false ) {
@mishterk
mishterk / ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass.php
Last active Sep 11, 2019
A hotfixed solution for bypassing custom database tables when using ACF's get_field() function. This will ONLY work with 1.0.x versions of the plugin. Version 1.1 will include built-in support for this capability.
View ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass.php
<?php
use ACFCustomDatabaseTables\Intercept\ACFGetFieldIntercept;
use ACFCustomDatabaseTables\Vendor\Pimple\Container;
/**
* Class ACFCDTvOneDotZeroDotAnyGetFieldInterceptBypass
*
* This provides a 'hotfixed' approach for disabling custom database table intercept when using ACF's get_field()
* function. This will only work with version 1.0.x versions of the plugin as a built-in tool will be available in
@mishterk
mishterk / count-new-members-between-two-dates.sql
Last active Sep 12, 2019
Helpful SQL queries for working with the MemberPress WordPress plugin
View count-new-members-between-two-dates.sql
SELECT count(DISTINCT txns.user_id)
FROM (
SELECT
user_id,
min(created_at) AS first_txn_created_at
FROM wp_mepr_transactions
WHERE status IN ('complete', 'confirmed')
GROUP BY user_id
) AS first_txns
INNER JOIN wp_mepr_transactions AS txns
View remove-margins-from-first-and-last-elements.css
.m-0-first-last > :first-child {
margin-top: 0;
}
.m-0-first-last > :last-child {
margin-bottom: 0;
}
@mishterk
mishterk / get-acf-sub-field-key-by-field-name-function.php
Last active Oct 1, 2019
A function for determining an ACF field's sub field key based on a field name. For more info see https://philkurth.com.au/tips/get-an-acf-sub-field-key-by-field-name/
View get-acf-sub-field-key-by-field-name-function.php
<?php
/**
* Locates an ACF sub-field by field name and returns the sub-field's key.
*
* This is particularly useful if you need to construct a data array for programmatic field
* update where a complex field is in use (e.g; repeater, group, flexi).
*
* @param string $sub_field_name The sub field name we need a key for.
* @param array $field The ACF field array.