Skip to content

Instantly share code, notes, and snippets.

View mwangepatrick's full-sized avatar

Patrick N. Mwange mwangepatrick

View GitHub Profile
<?php
/**
* The template for displaying all single posts
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/
(function($){
/**
* initializeBlock
*
* Adds custom JavaScript to the block HTML.
*
* @date 15/4/19
* @since 1.0.0
*
<section class="projects-arc">
<?php
$args = array(
'post_type' => 'project',
'post_status' => 'publish',
'order' => 'ASC',
'meta_key' => 'show_projects_archive',
'meta_value' => 'show',
);
$project = new WP_Query( $args );
@mwangepatrick
mwangepatrick / change_owner.sql
Created November 29, 2021 13:52
postgres: change database table owner
DO $$DECLARE r record;
DECLARE
v_schema varchar := 'public';
v_new_owner varchar := 'admin';
BEGIN
FOR r IN
select 'ALTER TABLE "' || table_schema || '"."' || table_name || '" OWNER TO ' || v_new_owner || ';' as a from information_schema.tables where table_schema = v_schema
union all
select 'ALTER TABLE "' || sequence_schema || '"."' || sequence_name || '" OWNER TO ' || v_new_owner || ';' as a from information_schema.sequences where sequence_schema = v_schema
union all
@mwangepatrick
mwangepatrick / acf_form_sample.php
Created November 16, 2021 12:33
How to create a post using the acf_form function
<?php
acf_form_head();
get_header();
//creating a frontend form
$options = array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
<?php
//print the student name & teacher name
//
$student = get_field('students');
?>
<h4>
Student (Child name): <?php echo $student["child_name"]; ?>
</h4>
<?php
$teachers = get_field('teachers_child_name');
<?php
$dateOfBirth = get_field('birth_date'); //date value returned in a valid date format
$today = date("Y-m-d");
$diff = date_diff(date_create($dateOfBirth), date_create($today));
echo 'Age is '.$diff->format('%y');
@mwangepatrick
mwangepatrick / repeater_sample.php
Created November 11, 2021 12:43
repeater_sample.php
<?php
//acf start code
echo "<h3>ACF Repeater section</h3>";
if( have_rows('students') ):
?>
<table>
<td>Student Name</td><td>Student Age</td><td>Courses</td>
<?php
<?php
global $wp_query;
$post = $wp_query->post;
$fw_og_title = get_field('og_title', $post->ID);
$fw_og_description = get_field('og_description', $post->ID);
$fw_og_image = get_field('og_image', $post->ID);
$fw_og_image_width = get_field('og_image_width', $post->ID);
$fw_og_image_height = get_field('og_image_height', $post->ID);
$fw_og_url= get_field('og_url', $post->ID);
?>
<?php
// filter
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'locations_$", "meta_key LIKE 'locations_%", $where);
return $where;
}