Skip to content

Instantly share code, notes, and snippets.

View dryan1144's full-sized avatar

David Ryan dryan1144

View GitHub Profile
<?php
function hck_filter_taxonomy_archives( $query_args, $sfid ) {
if( $sfid == 509 ) {
$query_args = array(
'post_type' => 'articles',
);
<?php
function hck_questions_cpt() {
$labels = array(
'name' => _x( 'Topics', 'healthcarekit' ),
'singular_name' => _x( 'Topic', 'healthcarekit' ),
'search_items' => __( 'Search Topics', 'healthcarekit' ),
'all_items' => __( 'All Topics', 'healthcarekit' ),
'parent_item' => __( 'Parent Topic', 'healthcarekit' ),
<?php
function hck_rewrite_post_types() {
add_rewrite_rule('^articles/([^/]*)/?','index.php?post_type=articles&topics=$matches[1]','top');
add_rewrite_rule('^questions/([^/]*)/?','index.php?post_type=questions&topics=$matches[1]','top');
add_rewrite_rule('^amas/([^/]*)/?','index.php?post_type=amas&topics=$matches[1]','top');
@dryan1144
dryan1144 / filter-taxonomy-term-url.php
Created July 26, 2017 00:13
Filter taxonomy term URLs for SF Pro
<?php
function hck_filter_taxonomy_archives( $url, $sfid) {
if (is_tax('topics')) {
$slug = get_queried_object()->slug;
$url = site_url() .'/'. get_post_type() .'/'. $slug;
}
return $url;
@dryan1144
dryan1144 / wp-rest-transient-example.php
Last active December 24, 2019 08:20
Sets a transient for elements in a WP REST API call
<?php
function yournamespace_rest_transient_example() {
//check for transient first
$data = get_transient( 'yournamespace_data_example' );
if ( !empty( $data ) ) {
$data = $terms_transient;
@dryan1144
dryan1144 / delete-transients.php
Last active December 24, 2019 20:11
Clear transient on post save
<?php
function yournamespace_delete_transient( $post_id, $post, $update ) {
delete_transient('yournamespace_data_example');
}
//{your_post_type} with a custom post type
add_action('save_post_{your_post_type}', 'yournamespace_delete_transient', 10, 3);
@dryan1144
dryan1144 / post-meta-transient.php
Last active December 24, 2019 20:12
Stores transient in post meta
<?php
/***
Stores persisent data as post meta instead of using Transient API
@param $post_id int post ID to store post meta for
@parm $meta_key str "transient" name
@param $update_func str function to update the meta key with a new value
@param $expiration time when value should expire
@dryan1144
dryan1144 / setup-meta-transient-rest-api.php
Created December 24, 2019 18:08
Define basic custom field and callback function
<?php
/***
Register custom field for existing endpoint with callback function
Endpoint: /wp/v2/your_post_type
Note: Could also be a custom endpoint using register_rest_route
***/
register_rest_field('your_post_type', 'custom_field_name', array(
<?php
/***
Allow a product to be added only once to cart
***/
function drw_edd_one_item_checkout( $download_id, $options ) {
if ( edd_item_in_cart($download_id) ) {
<?php
/***
Do something with payment data after purchase
***/
function drw_api_call_after_purchase( $payment_id ) {
$payment_meta = edd_get_payment_meta( $payment_id );