Home>Support>Get field instance by post Id

Get field instance by post Id

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

We have some project and use Vue.js. Now, our task is build template from json data that we will get via ajax.
Can i get $instance[‘some_filed’] via ajax by post_id?

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 5 years, 11 months ago Vitaly Dmitriev

    Afte some time of styding source code, i found a solution. Here is my function

    function get_widget_instance( $content, $widget_class ) {
    	$instance = null;
    	$post_blocks = parse_blocks($content);
    
    	if( ! empty( $post_blocks ) ) {
    		foreach( $post_blocks as $block ) {
    			$widgets = $block['attrs']['panelsData']['widgets'];
    			if( ! empty( $widgets ) ) {
    				foreach( $widgets as $widget ) {
    					if( $widget_class === $widget['panels_info']['class'] ) {
    						$instance = $widget;
    						break;
    					}
    				}
    			}
    		}
    	}
    
    	return $instance;
    }
    
  2. 5 years, 11 months ago Alex S
    Hi, I Work Here

    Hi Vitaly,

    Great to hear you were able to come up with a solution that works for your setup.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More