Skip to content

Instantly share code, notes, and snippets.

@dbranes
dbranes / functions.php
Last active October 31, 2018 13:44
Return ACF variable from wp-json (rest api & angular) @see http://www.wpquestions.com/question/showChrono/id/10627
/**
* Add ACF data to the WP JSON REST API
*/
add_filter( 'json_prepare_post', 'wpq_add_acf' );
function wpq_add_acf( $post ) {
if( function_exists( 'get_fields' ) )
{
@dbranes
dbranes / functions.php
Last active September 2, 2018 14:58
WordPress: Ajax (POST) to update post meta key
/**
* Update post meta key via ajax POST request
*
* @see http://wpquestions.com/question/showLoggedIn/id/10604
*
* On the remote site send a POST request to:
*
* http://example.tld/wp-admin/admin-ajax.php?action=update_post_meta
*
* with the following payload:
@dbranes
dbranes / functions.php
Last active May 21, 2018 07:36
WordPress: Inject custom post type posts, that are attached to a given term of a custom taxonomy, into the main loop and the feed.
/**
* Inject posts of the custom post type 'usp_post', that are attached to the 'featured' term of the
* 'firstpage' taxonomy, into the main loop and the feed.
* @see http://www.wpquestions.com/question/showChronoLoggedIn/id/10370
*/
add_filter( 'pre_get_posts', 'wpq_pre_get_posts', 99 );
function wpq_pre_get_posts( $query )
{
@dbranes
dbranes / functions.php
Last active November 3, 2017 12:56
Multiple comment forms and lists in single.php - wpquestions.com #9749
/**
* Example how to setup up multiple comment forms and comments lists
*
* @version 0.0.5
* @file functions.php
* @see http://www.wpquestions.com/question/showLoggedIn/id/9749
*/
/**
@dbranes
dbranes / wpq-search.php
Last active February 29, 2020 07:24
WooCommerce - search by product dimensions
<?php
/**
* Plugin Name: WooCommerce - Search by product dimensions, pa_colour and SKU
* Description: Shortcodes [wpq_search] and [wpq_results] to search products by length, height, width, attribute colour taxonomy and SKU
* Plugin URI: http://www.wpquestions.com/question/showChronoLoggedIn/id/9732
* Author: dbranes
* Version: 0.2.1
*/
/**
<?php
//Multi upload field - Insert images into WP media library and link them to post ID
add_action( 'gform_after_submission_20', 'my_add_post_attachements', 10, 2 );
function my_add_post_attachements( $entry, $form )
{
$submit = array();
$submit = $entry["38"]; //The field ID of the multi upload