Skip to content

Instantly share code, notes, and snippets.

View sachyya's full-sized avatar
🏠
Working from home

sachyya sachyya

🏠
Working from home
View GitHub Profile
@sachyya
sachyya / skip-post.php
Created February 7, 2024 08:11
Hide post with Thank you term
<?php
function custom_slug_skip_post( $skip, $post ) {
if( $post->post_type == 'resource' ) {
if (has_term('Thank You', 'resource-category', $post ) || has_term('Thank You', 'resource-tag', $post ) ) {
$skip = true;
}
}
return $skip;
}
@sachyya
sachyya / customization.php
Created February 6, 2024 10:00
Typesense Customization
<?php
function cm_typesense_format_resource_category_data ( $formatted_data, $raw_data, $object_id, $schema_name ) {
if ( $schema_name == 'resource' ) {
$terms = get_the_terms( $object_id, 'resource-category' );
$resource_categories = [];
foreach ( $terms as $term ) {
// Hide the "Thank you" category.
// skip "Thank You" category from being indexed
if( $term->name != 'Thank You' ) {
@sachyya
sachyya / sex-varitiona.php
Created December 28, 2023 08:00
Indexing Product Variations by Attribute
<?php
// Add sex variation to the schema
add_filter( 'cm_tsfwc_product_fields', 'your_slug_add_stock_status_to_schema' );
function your_slug_add_stock_status_to_schema( $product_fields ) {
$product_fields[] = [ 'name' => 'sex_variation', 'type' => 'string[]', 'facet' => true ];
return $product_fields;
}
// Data entry for sex_variation for indexing
add_filter( 'cm_tsfwc_data_before_entry', 'your_slug_add_data_before_entry', 10, 4 );
@sachyya
sachyya / multiple-cpt-in-one-index.php
Created July 28, 2023 07:26
Index multiple custom post types in one index
<?php
add_filter( 'cm_typesense_schema', 'add_schema', 10, 2 );
function add_schema( $schema, $name ) {
if ( $name === 'cpt_1' || $name = 'cpt_2' ) {
$schema['name'] = 'cpts-data';
$schema['fields] = [
[ 'name' => 'field_1', 'type' => 'string' ],
[ 'name' => 'field_2', 'type' => 'string' ],
];
@sachyya
sachyya / stock-status-to-schema.php
Created July 10, 2023 05:17
Add stock status to product schema
<?php
add_filter( 'cm_tsfwc_product_fields', 'your_slug_add_stock_status_to_schema' );
function your_slug_add_stock_status_to_schema( $product_fields ) {
$product_fields[] = [ 'name' => 'stock_status', 'type' => 'string' ];
return $product_fields;
}
add_filter( 'cm_tsfwc_data_before_entry', 'your_slug_add_data_before_entry', 10, 4 );
function your_slug_add_data_before_entry( $formatted_data, $raw_data, $object_id, $schema_name ) {
if( $schema_name === 'product' ) { // only add data if the schema is product
$stock_status = $raw_data->get_stock_status();
@sachyya
sachyya / .php
Created June 28, 2023 04:52
Add ACF fields for indexing
<?php
// Step 1
// Adding the ACF field to schema to be indexed
function cm_typesense_add_acf_field_to_schema( $schema, $name ) {
if ( $name == 'post' ) { // change post to your schema name
$schema['fields'][] = [ 'name' => 'acf_field', 'type' => 'string' ]; //
}
return $schema;
@sachyya
sachyya / .php
Created June 27, 2023 04:58
Adding job location to TS server
<?php
function cm_typesense_add_available_post_types( $available_post_types ) {
$available_post_types['job_listing'] = [ 'label' => 'job_listing', 'value' => 'job_listing' ];
return $available_post_types;
}
add_filter( 'cm_typesense_available_index_types', 'cm_typesense_add_available_post_types');
//only necessary if the default post schema is not necessary
function cm_typesense_add_job_listing_schema( $schema, $name ) {
@sachyya
sachyya / posts-tag-index.php
Last active June 8, 2022 10:07
Index posts' tags in Typesense
<?php
add_filter( 'cm_typesense_schema', 'your_slug_add_tags', 10, 2 );
function your_slug_add_tags( $schema, $name ) {
if( 'post' === $name ) {
$schema['fields'][] = [ 'name' => 'tags', 'type' => 'string[]', 'facet' => true ];
}
return $schema;
}
add_filter( 'cm_typesense_data_before_entry', 'your_slug_tags_data', 10, 4 );
@sachyya
sachyya / move-cat-filter.php
Last active May 2, 2022 05:40
Move default Category filter below custom filters in Typsense Search for WooCommerce
<?php
$tmpl_hook_obj = Codemanas\Typesense\WooCommerce\Main\TemplateHooks::get_instance();
remove_action( 'cm_tsfwc_filter_panel_output', [ $tmpl_hook_obj, 'category_filter' ], 5 ); //This must be 5
add_action( 'cm_tsfwc_filter_panel_output', [ $tmpl_hook_obj, 'category_filter'], 18 ); // You can change the priority as per your requirement.
@sachyya
sachyya / Making devilbox multisite
Last active March 2, 2025 06:22
Make WP multisite in devilbox
Steps:
Copy to .devilbox files like apache22.yml and nginx.yml as per docs.
When subdomain is added. Add them to /etc/hosts too
Detailed step
1. Create `.devilbox` folder inside the project at `htdocs` level.
2. Copy related ngnix/apache file from `cfg/vhost-gen` folder
3. Once copied rename it to `.nginx` or `.apapche`
4. Then change the code as mentioned in the docs