Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have the exact same issue screenshot

    • This reply was modified 3 years, 4 months ago by markilfin.
    Thread Starter markilfin

    (@markilfin)

    Thank you for your quick answer. Yes, this helped me a lot.

    Thread Starter markilfin

    (@markilfin)

    Here is how i did it:
    1. i added data-id for every post
    <article <?php post_class( 'single-slide' ); ?> id="post-<?php the_ID(); ?>" data-id="<?php the_ID(); ?>"></article>
    2. via js i’m collecting these ids and redirect the page with predefined parameter posts_to_clone:

    const button = document.getElementById('clone-all-slides');
    button.addEventListener('click', () => {
    	let slides = document.getElementsByClassName('single-slide');
    	let ids = '';
    	for (let i = 0; i < slides.length; i++) {
    		ids += (slides.length - 1) !== i ? <code>${slides[i].dataset.id},</code> : <code>${slides[i].dataset.id}</code>;
    	}
    	window.location.href = <code>${window.location.href}wp-admin/edit.php?posts_to_clone=${ids}</code>;
    });

    3. in functions.php i’m checking if parameter posts_to_clone exists and if it does, i’m making clone for every id it has via duplicate_post_create_duplicate:

    function frontend_bulk_clone () {
    	if ( is_admin() && isset( $_GET['posts_to_clone'] ) ) {
    		$posts_to_clone = ( explode( ',', $_GET['posts_to_clone'] ) );
    		foreach ( $posts_to_clone as $post_id ) {
    			$post = get_post( $post_id );
    			if ( ! empty( $post ) ) {
    				if ( ! is_post_type_hierarchical( $post->post_type ) || is_post_type_hierarchical( $post->post_type ) ) {
    					duplicate_post_create_duplicate( $post );
    				}
    			}
    		}
    		wp_redirect( get_site_url() . '/user', 301 );
    		exit;
    	}
    }
    add_action( 'wp', 'frontend_bulk_clone' );

    I know, this is a little bit dirty, but it works.
    Any improvements or remarks are welcome.
    Thanks!

    • This reply was modified 4 years, 10 months ago by markilfin.
    Thread Starter markilfin

    (@markilfin)

    Ok, thank you! I can do it myself, just wanted to know if maybe such option already realized and just not mentioned in docs.

    Thread Starter markilfin

    (@markilfin)

    Yes, of course.
    For example, we have two blocks: 1. sidebar with filters; 2. and main content area with products.
    Lets say user has selected “t-shirts” and “size 6” from our filters. So these are our “active filters”.
    Meanwhile, in content area with our products, i want to show a text block with info: “You choose: {list with our active filters}”.

    Something similar to this https://prntscr.com/phof36

Viewing 5 replies - 1 through 5 (of 5 total)