/* 
Theme Name:		Hello Elementor Child
Theme URI:		https://elementor.com/
Description:	Hello Elementor Child is a child theme of Hello Elementor, created by Elementor team
Author:			Elementor Team
Author URI:		https://elementor.com/
Template:		hello-elementor
Version:		1.0.0
Text Domain:	hello-elementor-child
Tags:           flexible-header, custom-colors, custom-menu, custom-logo, editor-style, featured-images, rtl-language-support, threaded-comments, translation-ready
*/

/*
    Add your custom styles here
*/
/**
 * Get like count - Code by LEMON SHLIF, Visit LMN.co.il
 */
function lmn_like_image_get() {
    if (!isset($_POST['image_id'])) {
        wp_send_json_error();
    }

    $id = intval($_POST['image_id']);
    $likes = get_post_meta($id, 'lmn_image_likes', true) ?: 0;

    $liked = isset($_COOKIE['lmn_liked_' . $id]);

    wp_send_json_success([
        'likes' => $likes,
        'liked' => $liked
    ]);
}
add_action('wp_ajax_lmn_like_image_get', 'lmn_like_image_get');
add_action('wp_ajax_nopriv_lmn_like_image_get', 'lmn_like_image_get');


add_filter( 'elementor_pro/forms/render_field', function( $field, $item ) {

    // שנה כאן את ה-ID של השדה שלך בטופס
    if( $field['id'] === 'dynamic_post_select' ) { 

        // כאן מגדירים את סוג הפוסט (CPT או post רגיל)
        $posts = get_posts( array(
            'post_type' => 'your_cpt',  // החלף בשם ה-CPT שלך, לדוגמה 'movies'
            'posts_per_page' => -1,     // כל הפוסטים
            'orderby' => 'title',       // אפשר גם 'date' או 'ID'
            'order' => 'ASC'
        ));

        $options = array();
        foreach( $posts as $post ) {
            $options[ $post->ID ] = $post->post_title;  // הערך יהיה ID, הטקסט יהיה הכותרת
        }

        $field['options'] = $options;
    }

    return $field;

}, 10, 2 );

