PHP code example of spock / shadow-taxonomies

1. Go to this page and download the library: Download spock/shadow-taxonomies library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spock / shadow-taxonomies example snippets


add_action( 'init', function() {
	register_taxonomy(
		'services-tax',
		'staff-cpt',
		array(
			'label'         => __( 'Services', 'text-domain' ),
			'rewrite'       => false,
			'show_tagcloud' => false,
			'hierarchical'  => true,
		)
	);
    // We will make our connection here in the next step.
});

\Shadow_Taxonomy\Core\create_relationship( 'service-cpt', 'service-tax' );

\Shadow_Taxonomy\Core\register_shadow_taxonomy(
	[ 'movies' ],
	[ 'actor' ],
	'_actor',
	[
		'label'         => 'Actors',
		'rewrite'       => false,
		'show_tagcloud' => false,
		'show_ui'       => false,
		'hierarchical'  => false,
		'show_in_menu'  => false,
		'meta_box_cb'   => false,
		'show_in_rest'  => true,
	]
);


get_the_posts( $post_id, $taxonomy, $cpt )

wp shadow sync --cpt=cpt_slug --tax=taxonomy_slug
// Will sync all of the input custom post types by creating terms in the input taxonomy.
wp shadow sync --cpt=cpt_slug --tax=taxonomy_slug --dry-run
// Will output a table of the changes the script will make without actually making any changes.
wp shadow sync --cpt=cpt_slug --tax=taxonomy_slug --verbose
// Will sync the terms but also output more logs as it process your data.