Skip to content

Instantly share code, notes, and snippets.

View XanderCalvert's full-sized avatar
💭
probably coding PHP

Matt Calvert XanderCalvert

💭
probably coding PHP
View GitHub Profile
@XanderCalvert
XanderCalvert / 1.php
Last active June 19, 2022 12:22
Gutenberg false
<?php
add_filter('use_block_editor_for_post', '__return_false');
@XanderCalvert
XanderCalvert / gbv.jsx
Last active May 24, 2022 21:55
Gutenberg Block Validation
const Edit = ( props ) => {
//... other functions
useEffect(() => {
// console.log( items.length );
if ( items.length == 0 ) {
if ( ! locked ) {
@XanderCalvert
XanderCalvert / useEffect.jsx
Created May 24, 2022 21:44
Importing useEffect
//... other imports
import React, { useState, useEffect } from 'react';
let locked = false;
@XanderCalvert
XanderCalvert / class.jsx
Created May 24, 2022 21:40
Functional Component vs Class
// Class 👎
class Edit extends Component {
}
// Functional Components 👍
const Edit = ( props ) => {
}
<?php
private function define_public_hooks() {
//Query modification
$this->loader->add_filter( 'pre_get_posts', $plugin_public, 'podcast_adjust_queries' );
$this->loader->add_filter( 'template_include', $plugin_public, 'podcast_adjust_archive' );
}
<?php
public function podcast_adjust_queries($query){
if ( ! is_admin() && is_post_type_archive( 'podcast' ) && $query->is_main_query() ) {
// if options to exclucde
$inc_articles = get_option( 'options_include_audio_articles_in_podcast_archive' );
if ( $inc_articles ) {
$query->set( 'post_type', array( 'podcast', 'articles' ) );
<?php
public function podcast_adjust_archive( $template ){
global $wp_query;
if ( $wp_query->query_vars['is_podcast_archive'] == 1 ) {
$new_template = locate_template( array( 'archive-podcast.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
@XanderCalvert
XanderCalvert / template.php
Created April 11, 2022 22:41
podcast and archive template
<?php
switch ( get_post_type() ){
case "podcast":
get_post_type();
?>
<h3 class="fancy"><?php _e('Featured Podcast');?></h3>
<p class="podcast-published"><?php echo get_podcast_duration($post->ID) . '&nbsp;&nbsp;&nbsp;' . get_the_date(); ?></p>
<a href="<?php echo get_the_permalink($post);?>"><h2 class="h3"><?php echo get_the_title($post);?></h2></a>
<p><?php echo get_dynamic_excerpt($post); ?></p>
@XanderCalvert
XanderCalvert / plugin.php
Created April 11, 2022 22:16
filters for wordpress query
private function define_public_hooks() {
//Query modification
$this->loader->add_filter( 'pre_get_posts', $plugin_public, 'podcast_adjust_queries' );
$this->loader->add_filter( 'template_include', $plugin_public, 'podcast_adjust_archive' );
}
@XanderCalvert
XanderCalvert / 1.php
Created April 11, 2022 22:10
Function adjusting main query in Wordpress
public function podcast_adjust_queries($query){
if ( ! is_admin() && is_post_type_archive( 'podcast' ) && $query->is_main_query() ) {
// if options to exclude
$inc_articles = get_option( 'options_include_audio_articles_in_podcast_archive' );
if ( $inc_articles ) {
$query->set( 'post_type', array( 'podcast', 'articles' ) );
$query->set( 'posts_per_page', 1 );
$query->set( 'is_podcast_archive', 1 );
$query->set( 'meta_query', array(
array( //meta_key for the articles which I am searching for