Skip to content

Instantly share code, notes, and snippets.

View mwangepatrick's full-sized avatar

Patrick N. Mwange mwangepatrick

View GitHub Profile
@mwangepatrick
mwangepatrick / bidirectional-relationship.php
Created July 21, 2023 08:14
Setting up Bidirectional relation across different post types
add_action( 'acf/save_post', 'my_acf_save_post_test' );
function my_acf_save_post_test( $post_id ) {
if ( 'post' == get_post_type( $post_id ) ) {
$my_related_pages = get_field( 'my_related_page', $post_id, false );
error_log(json_encode($my_related_pages));
foreach ( $my_related_pages as $page ) {
// selected page
$related_posts = get_field( 'my_related_post', $page, false );
if(!$related_posts){
update_field( 'my_related_post', array($post_id), $page );
@mwangepatrick
mwangepatrick / my_acf_fields_user_result.php
Created April 26, 2023 06:52
How to modify the ACF user object results
<?php
add_filter('acf/fields/user/result', 'my_acf_fields_post_object_result', 10, 4);
function my_acf_fields_post_object_result( $text, $user, $field, $post_id ) {
$text .= ' (' . $user->user_email . ')';
return $text;
}
function register_custom_fields() {
$fieldArray = [];
array_push($fieldArray,
array(
'key' => 'sample_field_onee',
'label' => 'Sample Field',
'type' => 'text',
<?php
$current_date = date( 'md' ); // first load the current date into a variable, formatted as md
$employee_birthdays = new WP_Query(
array(
'posts_per_page' => -1,
'post_type' => 'member', // employee
'meta_query' => array(
array(
'key' => 'birthday', // assumes the date picker field is called birthday. Stored in Ymd format.
/* package whatever; // don't place package name! */
import java.io.*;
public class myCode
{
public static void main(String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
/* package whatever; // don't place package name! */
import java.io.*;
public class myCode
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Scanner;
class HelloWorld {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in); // Reading from System.in
//Enter the number of items to input
System.out.println("Enter a number: ");
(function($){
/**
* initializeBlock
*
* Adds custom JavaScript to the block HTML.
*
* @date 15/4/19
* @since 1.0.0
*
<?php
/**
* Testimonial Block Template.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
*/
<?php
/**
* Newton Block Template.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
*/