Support

Account

Home Forums Search Search Results for '%s'

Search Results for '%s'

topic

  • Unread

    Comparing numeric values is not working Help

    i m making just a small filter a simple real estate filter ( nature, type, location, price_range) all fields worked and just price range is not working properly knowing that i flowed your official Guide demo of my website LINK

    get_header(); ?>
    
    	<section id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
            <?php //print_r($_GET); ?>
    		<?php if ( have_posts() ) : ?>
    
    			<header class="page-header">
    				<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'alizee' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    			</header><!-- .page-header -->
    
                 <!--BEGNI-->
    
    			 <?php 
    
    			
                if ($_GET['prix'] == "50000"){
    			   $prix_min = 0;
    			   $prix_max = 50000;
    			}
    			if ($_GET['prix'] == "100000"){
    				$prix_min = 50000;
    				$prix_max = 100000;
    			}
    			if ($_GET['prix'] == "500000"){
    				$prix_min = 500000;
    				$prix_max = 1000000;
    			}
    			if ($_GET['prix'] == "10000000"){
    				$prix_min = 500000;
    				$prix_max = 10000000;
    			}
    			if ($_GET['prix'] == "Tout"){
    				$prix_min = 0;
    				$prix_max = 100000000;
    			}
    			
    			$posts = get_posts(array(
    				'numberposts'	=> -1,
    				'post_type'		=> 'post',
    				'orderby'  => 'meta_value_num', 
    				'order' => 'ASC',
    				'meta_query'	=> array(
    					'relation'		=> 'AND',
    
    					array(
    						'key'	  	=> 'prix',
    						'value' => array($prix_min, $prix_max),
    						'compare' => 'BETWEEN',
    						'type' => 'NUMERIC'
    					),
    					array(
    						'key'	  => 'type',
    						'value'   => $_GET['nature'],
    						'compare' => '=',
    					),
    					array(
    						'key'	  => 'categorie',
    						'value'   => $_GET['categorie'],
    						'compare' => '=',
    					),
    					array(
    						'key'	  => 'adresse',
    						'value'   => $_GET['location'],
    						'compare' => '=',
    					),
    
    				),
    			));
    
    			if( $posts ): ?>
    	
    				<ul>
    					
    				<?php foreach( $posts as $post ): 
    					
    					setup_postdata( $post );
    					
    					?>
    					<li> 
    						<?php get_template_part( 'content', 'search' ); ?>
    					</li>
    				
    				<?php endforeach; ?>
    				
    				</ul>
    	
    			<?php wp_reset_postdata(); ?>
    
    			<?php endif; ?>
    
    			 <!--END--->
    
    			<?php alizee_paging_nav(); ?>
    
    		<?php else : ?>
    
    			<?php get_template_part( 'content', 'none' ); ?>
    
    		<?php endif; ?>
    
    		</main><!-- #main -->
    	</section><!-- #primary -->
    	<?php echo get_search_query(); ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    
  • Solving

    How to Upgrade Simple Fields to ACF 5

    I recently had to update some sites from the discontinued Simple Fields plugin to ACF. I hope this might help someone.

    The steps below are non-destructive, nothing is deleted. This process duplicates your Simple Fields data to a format that ACF 5 uses. It’s up to you to go and clean up the old Simple Fields data from your database if you wish. Please test on a non-production site first to get working!

    Step By Step

    1. Create a new ACF field group that matches the old Simple Fields group. ACF stores information about the new fields in the wp_posts table. You don’t need to mess with this. What we will be doing is migrating your Simple Field data over to a format the ACF recognizes. This will happen in the wp_postmeta table.
    2. You should now have two similar looking Field Group boxes in your content type editing screen.
    3. Now you need to track down the Simple Field names. They are in the format “_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0”. Each field group is a unique integer and each field within each group is also a unique integer. You can run an SQL query like ‘SELECT meta_key,meta_value FROM wp_postmeta where meta_key LIKE ‘%simple_field%’;’. This should show you all your Simple Field’s keys and values.
    4. For each Simple Field we’ll need to grab every Post ID and the actual value of the field.
    5. Then using this data we’ll insert two new rows of data for every matching ACF field.
    6. It’s probably best to do steps 4 and 5 with code. I’ve included some sample starter code below of how to extract the Simple Field info and create two new rows of field data for ACF to use. Certainly power users could implement everything in a monster sql query.
    7. Important – Update all your template and perhaps function.php code to use ACF to retrieve custom field data. Ideally you should have this done and ready to implement before you migrate the data.
    8. Disable Simple Fields plugin and clean up Simple Fields rows from your database if you wish.

    
    /*** Sample PHP Code ***/
    
    /* Simple Fields to ACF Migrator */
    
    // PDO Database Connection
    $dsn = "mysql:host=your-host-here;dbname=your-database-name-here";
    $user = "your-db-username";
    $passwd = "your-db-password";
    
    $pdo = new PDO($dsn,$user,$passwd);
    
    // SQL for Selecting all the existing Simple Field data. Each query is field. I put them in an array so we can iterate through them. 
    // Example below is for three custom Simple Fields that form one field group. Substitute your field names for the values.
    // There are two sub select statements in these queries that use the new ACF field name and also grab its machine name. Important - This is where you match each Simple Field to its new ACF counterpart.
    $simple_fields = array(
    	"SELECT post_id, meta_value, (SELECT post_excerpt from {$wp_posts} WHERE post_excerpt = 'acf_field_1' AND post_type = 'acf-field') AS acffieldname, (SELECT post_name from {$wp_posts} WHERE post_excerpt = 'acf_field_1' AND post_type = 'acf-field') AS acfrealfieldname FROM {$wp_postmeta} WHERE meta_key = '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0'",
    	"SELECT post_id, meta_value, (SELECT post_excerpt from {$wp_posts} WHERE post_excerpt = 'acf_field_2' AND post_type = 'acf-field') AS acffieldname, (SELECT post_name from {$wp_posts} WHERE post_excerpt = 'acf_field_2' AND post_type = 'acf-field') AS acfrealfieldname FROM {$wp_postmeta} WHERE meta_key = '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0'",
    	"SELECT post_id, meta_value, (SELECT post_excerpt from {$wp_posts} WHERE post_excerpt = 'acf_field_3' AND post_type = 'acf-field') AS acffieldname, (SELECT post_name from {$wp_posts} WHERE post_excerpt = 'acf_field_3' AND post_type = 'acf-field') AS acfrealfieldname FROM {$wp_postmeta} WHERE meta_key = '_simple_fields_fieldGroupID_1_fieldID_3_numInSet_0'"
    );
    
    // Iterate over each field executing its select query to grab the data, and pass it to a function to insert the two new rows of ACF data
    foreach ($simple_fields as $field) {
    	$rows = updateSimpleFieldsToAcf($pdo,$field);
    }
    
    // Simple function to take each field's data and insert into wp_postmeta in ACF format
    function updateSimpleFieldsToAcf($pdo,$sql) {
    
    	// Prepare and execute each field's sql statement.
    	$stm = $pdo->prepare($sql);
    	$stm->execute();
    	
    	// grab all the rows in an array, we will now iterate over each of these rows and insert our two new rows
    	$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
    	// Our basic sql statement for inserting the new data
    	// Remember if you're on WordPress multisite or externally hosted your table names may have an integer prefix, e.g. wp_13_postmeta
    	$sql1 = "INSERT INTO wp_postmeta (<code>post_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES (?,?,?)";
    	
    	// Iterate over each row and perfom two inserts
    	foreach($rows as $row) {
    		// You can clean up or manipulate the selected data here and place in variables to insert. 
    		$row_post_id = $row['post_id']; // post id
    		$row_field_name = $row['acffieldname']; // acf field name
    		$u_row_field_name = "_" . $field_name; // acf field name prepended with underscore
    		$row_clean_value = $row['meta_value']; // actual value of field, may need to clean up character encoding or such here.
    		$row_real_field_name = $row['acfrealfieldname']; // machine name of acf field e.g. field_5d94f173d6daa
    		
    		// First row insert - post_id, field_name, cleaned meta_value
    		//$sql_first_row = "INSERT INTO {$q_tablename} (<code>post_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES (<code>{$row['post_id']}</code>, <code>{$field_name}</code>, <code>{$clean_value}</code>)";
    		$stm1 = $pdo->prepare($sql1);
    		$stm1->bindValue(1, $row_post_id, PDO::PARAM_INT);
    		$stm1->bindValue(2, $row_field_name, PDO::PARAM_STR);
    		$stm1->bindValue(3, $row_clean_value, PDO::PARAM_STR);
    		$result = $stm1->execute(); // should implement some error checking on your result e.g. if (!$result) check $stm1->errorInfo etc.
    		
    		//$sql_second_row = "INSERT INTO {$q_tablename} (<code>post_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES (<code>{$row['post_id']}</code>, <code>{$u_field_name}</code>, <code>{$row['acfrealfieldname']}</code>)";
    		$stm2 = $pdo->prepare($sql1);
    		$stm2->bindValue(1, $rpw_post_id, PDO::PARAM_INT);
    		$stm2->bindValue(2, $u_row_field_name, PDO::PARAM_STR);
    		$stm2->bindValue(3, $row_real_field_name, PDO::PARAM_STR);
    		$result = $stm2->execute(); // again, no error checking
    	}
    }
    
    /* End Sample Code */
    

    SUMMARY – It’s moderately easy to migrate all your data and fields from Simple Fields to ACF. You first duplicate the fields groups in ACF. Then select the existing Simple Fields one by one and match the field and data with its new ACF counterpart. Using this data, you create two new rows of data in the postmeta table that’s in a fromat ACF recognizes. Your new ACF fields will automatically use the new field values. Don’t forget you have to update your template code to call the ACF fields instead of Simple Fields. You can also delete the rows of Simple Field data if you are so inclined.

  • Helping

    How do I add submit button to field by field form?

    I have a very long form that creates a custom post type. Because its so long it has to be broken up on the front end and I am doing so by using acf_form and using the ‘fields’ setting. Example:

    $optionsLocation = array(
    ‘fields’ => array(‘field_5d1295443db3f’),
    ‘updated_message’ => false,
    ‘form’ => false,
    );
    acf_form($optionsLocation);

    How do I create the submit button that will submit the form on the page? If I do something lke the following I get the button and it looks like it’s submitting but post is not created:

    $optionsLocation = array(
    ‘field_groups’ => false,
    ‘fields’ => false,
    ‘updated_message’ => false,
    ‘html_submit_button’ => ‘<input type=”submit” class=”acf-button button button-primary button-large” value=”%s” />’,
    ‘form’ => true,
    );
    acf_form($optionsLocation);

    Help?

  • Solved

    Setting Field values using the Javascript API

    I’m using Javascript to add a layout to a Flexible Content field and set values on the fields therein. Here’s the relevant bit of code:

    
    /* 
    This isn't the real data, just giving you an idea of what it looks like. 
    That is not a spread operator at the end :) 
    */
    var l = { layout: 'my_layout', data: [ 'heading' => 'My Heading Content', 'text' => 'the text', ...]};
    
    /*
    fcField is the Flexible Content field. I know this part is working correctly.
    */
    var added = fcField.add({ layout: l.layout });
    
    for (var name in l.data) {
        var key = added.find(<code>[data-name=&quot;${name}&quot;]</code>).attr('data-key');
    
        /*
        This line feels pretty clunky but I didn't see a better way to do this.
        */
        var subField = acf.getField(acf.findField(key, added));
        var val = l.data[name];
    
        /*
        This notice is appearing on all of the fields I'm targeting, exactly like I would expect
        */
        subField.showNotice({
            text: 'Set field value to “' + val + '”',
            type: 'success',
            dismiss: true
        });
    
        console.log('Set %s to %s', name, val);
    
        /*
        This doesn't seem to do anything if subField is a WYSIWYG or Image (and probably other types too)
        */
        subField.val(val);
    }
    

    This is *kinda* working. I know the subField variable is the subfield in the newly generated layout clone like I want. The field *notices* are appearing on every field, and my logs are all looking like what I would expect, but for some reason the values aren’t getting set on my WYSIWYG and Image fields. My gut tells me some kind of JS initialization is getting skipped… but I’m at a loss as to what that could be.

    Any ideas?

  • Unread

    Save/Update Post doesnt work (ACF Pro)

    Hi. I have the ACF Pro Developer Licence, and i have a problem on a page where ACF Frontend form doesnt save/update. It used to work, but i didnt noticed when it stopped working.

    The Page i have this form is WooCommerce Thank You page (thankyou.php). Also i have the form on another page (post-edit.php) and it works good there..
    Could be some issue with WooCommerce?

    The code is here

    
    <?php
    
    $items = $order->get_items();
    	foreach ( $items as $item ) {
        $product_name = $item->get_name();
        }
    $subscription_number = $order->get_order_number();
    $subscriptions_by = wcs_get_subscriptions_for_order( $subscription_number );
    	foreach ( $subscriptions_by as $singlesubid ) {
    	$subscrip_name = $singlesubid->get_order_number();
    	$subscrip_post_id = get_field('field_5c79b1a176e99', $subscrip_name);
        }
    ?>
    
    <?php /* THE FORM */ ?>
    
    <div id="content" class="site-content" role="main">
                                <?php /* The loop */ ?>
                                <?php while ( have_posts() ) : the_post(); ?>
                                <?php acf_form_head(); ?>
                                <?php acf_form(array(
    					'post_id'	=> $subscrip_post_id,
    					'post_title'	=> true,
    					'submit_value'	=> 'Save Opportunity',
    					'field_groups' => array('group_5c0fe3040af7f'),
    					'uploader' => 'basic',
    					'updated_message' => __("Opportunity is now updated", 'acf'),
    					'html_submit_button'	=> '<input type="submit" class="acf-button button submit-opportunity" value="%s" />',
    				/* 	'return' => '/my-account/my-opportunities/', */
    				)); ?>
    
                                <?php endwhile; ?>
                            </div>

    Thanks

  • Helping

    Categories in Shortcode – Get Image

    Hey there,

    I am registering the below shortcode to generate a list of categories on any page. The categories have an ACF field for the image.

    function categories_display() {
    
        $categories = get_categories( array(
            'orderby' => 'name',
            'order'   => 'ASC',
            'show_count'         => 1,
        ) );
        ob_start();
        ?>
        <div class="container">
            <div class="row border rounded p-2 mb-4">
                <?php foreach ($categories as $category ) : 
                    
                    // get the current taxonomy term
                    $term = get_queried_object();
    
                    // vars
                    $image = get_field('image', $term);
    
                    $category_link = sprintf( 
                        '<a href="%1$s" alt="%2$s">%3$s</a>',
                        esc_url( get_category_link( $category->term_id ) ),
                        esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
                        esc_html( $category->name )
                    );
                    
                    ?>
                    <div class="col-xs-12 col-sm-6 col-md-4 p-4 p-md-1 p-xl-1 text-center d-flex justify-content-between flex-column">
                        <div class="cat-child-name"><p><?=$category_link?></p></div>
                        <div class="cat-child-image"><a href="<?php echo get_category_link( $category->term_id ); ?>"><img class="img-fluid" src="<?php echo $image['url']; ?>" /></a></div>
                    </div>
                <?php endforeach;?>
            </div>
        </div>
        
        <?php $content = ob_get_clean();
        return $content;
     }
    add_shortcode( 'wp_categories_display', 'categories_display' );

    The image isn’t loading at all. It just returns nothing.

    What am I doing wrong?

    Thanks
    Chris

  • Solving

    Can not get repeater row/data on search page (search.php)

    Hello all,
    Hope you all are having a good day. I am facing an unusual issue while trying to get repeater data from posts on search page. Simple text fields are showing data fine, but when trying to get data from repeater rows I get nothing. I am pasting the complete code from the search file here. As you will notice I have tried all possible ways but noting works. line number 94: the_field(‘alternate_title’, $post->ID); this works but repeater entries are not showing.

    Thanks in advance.

    <?php
    /**
     * The template for displaying search results pages
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
     *
     * @package H2
     */
    
    get_header();
    ?>
    <?php 
    $rows = get_field('activities');
    var_dump('<hr><pre>', $rows);
    if($rows)
    {
        echo '<ul>';
    
        foreach($rows as $row)
        {
            echo '<li>sub_field_1 = ' . $row['title'] . ', etc</li>';
        }
    
        echo '</ul>';
    }
     ?>
    <ul>
    <?php foreach (get_field('activities', 60) as $row) :?>
        <li><?php print $row['title'] ?></li>                  
    <?php endforeach; ?>
    </ul>
    <?php
    
    global $query_string;
    //var_dump('<pre>', $_GET["s"]);
    //var_dump('<pre>', wp_parse_str( $query_string, $search_query ));
    // args
    
    // $search_query = array(
    //     'post_type' => 'math',
    //     'meta_query' => array(
    //         array(
    //             'key' => 'activities_$_title',
    //             'value' => $_GET["s"],
    //             'compare' => '='
    //         )
    //     )
    // );
    wp_parse_str( $query_string, $search_query );
    
    $search = new WP_Query( $search_query ); 
    //var_dump('<pre>', $search); ?>
    
    <style type="text/css">
        i {font-size: 12px;}
    </style>
    	<main class="site-main math-base">
            <div class="container">
                <div class="row">
                    <div class="left-col xo-col">
                        <?php //get_template_part( 'template-parts/sidebar', 'left' ); ?>
                        <div class="math-nav-div">
                            <?php h2_menu('footer-one', 'nav-menu') ?>
                                
                            <form action="<?php echo home_url( '/' ) ?>" method="get" role="search">
                                <div class="input-with-btn">
                                    <label class="work-around" for="search6">Search the Math</label>
                                    <input type="search" id="search6" class="form-control" name="s" placeholder="Type Here" value="<?php the_search_query(); ?>">
                                    <input type="hidden" name="post_type" value="math">
                                    <button class="btn" type="submit"><span class="fa fa-search"></span><span class="work-around">Search here</span></button>
                                </div> 
                            </form>
                                
                        </div>
                    </div>
                    <div class="col-80 xo-col">
    
                            <header class="page-header">
                                <h1 class="page-title">
                                    <?php
                                    /* translators: %s: search query. */
                                    printf( esc_html__( 'Search Results for: %s', 'h2' ), '<span>' . get_search_query() . '</span>' );
                                    ?>
                                </h1>
                            </header><!-- .page-header -->
                            <?php if( $search->have_posts() ): 
                                while ( $search->have_posts() ) : $search->the_post();
                                    if(get_post_type()=='math'):
                                        the_title();
                                        echo "<i>after title</i><hr>";
                                        echo $post->ID;
                                        echo "<i>after id</i><hr>";
                                        the_field('alternate_title', $post->ID);
                                        echo "<i>after alternate_title</i><hr>";
                                        the_field('subdomains', $post->ID);
                                        
                                        echo get_post_type(); ?>
    
                                        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
                                            <?php if( have_rows('activities', $post->ID) ): ?>
                                                <?php echo $count = 0; ?>
                                                
                                                <?php while( have_rows('activities', $post->ID) ): the_row();
                                                    // vars
                                                    $title = get_sub_field('title');
                                                    $primary_content_standards = get_sub_field('primary_content_standards');
                                                    $primary_math_practices = get_sub_field('primary_math_practices');
                                                    $description = get_sub_field('description'); ?>
    
                                                    <div class="search-result-wrap">
                                                        <h2><?php echo $title; ?></h2>
                                                        <?php echo $description; ?>
    
                                                        <h3>Primary Content Standards Addressed by Resource: <small><?php echo $primary_content_standards; ?></small></h3>
                                                        <h3>Primary Math Practices Addressed by Resource: <small><?php echo $primary_math_practices; ?></small></h3>
                                                    </div>
                                                <?php endwhile; ?>
                                                
                                            <?php endif; ?>
                                        </article><!-- #post-<?php the_ID(); ?> -->
                                        
                                    <?php endif;
                                endwhile;
                               
                            endif; ?>
    
                    </div>
                </div>
            </div>
        </main>
    <?php
    get_footer();
    
  • Helping

    Using ACF Forms and default user fields?

    Hey guys,

    I’ve recently created my first ACF form using code such as:

    
    // ACF Form settings
    $settings = array(
        'id' => 'contractor-form',
        'post_id' => 'user_' . get_current_user_id(),
        'field_groups' => array(418),
        'post_content' => false,
        'uploader' => 'basic',
        'return' => '',
        'submit_value' => __('Finish Registration', 'acf'),
        'updated_message' => false,
        'label_placement' => 'left',
        'html_submit_button'	=> '<input type="submit" value="%s" />',
    );
    
    // Register our ACF form for usage in our template
    acf_register_form( $settings );
    

    …and then outputting the form later with acf_form and everything is working fine; however was wondering if you can also use the form to update default user fields as well as ACF fields?

    Reason I ask is because I want to collect the first name and last name, but don’t want to double up on the fields, but more importantly want to be able to update the users email address from the frontend as well.

    Is something like this possible?

  • Helping

    complex query between objects

    Hello,

    I’ve been trying to achieve something and I can’t figure out how to do…

    First of all let me explain what I have :

    – I have a custom post type call student, with a post_title (the student full name) and an objet called “parent”, of type user

    – I have my users who have custom fields like firstname, lastname, address, etc.

    What I need to do is : search for all the students whose name contains a given string OR their parent’s name.

    I tried to use get_posts to achive that but I didn’t succeed.
    So I tried with wpdb, thinking I could write the sql query more easily but that’s not the case…

    For now I have :

    query 1:
    SELECT * FROM wp_posts WHERE
    post_status LIKE ‘publish’
    AND post_type LIKE ‘student’
    AND post_title LIKE ‘%$searched_string’

    It’s working fine, it was not the hardest part 🙂

    On the other hand I tried to get all the users whose first of lastname contains the string, so I have this query :

    query 2:
    SELECT * FROM wp_users u
    INNER JOIN wp_usermeta um
    ON um.user_id = u.ID
    WHERE um.meta_key = ‘first_name’
    AND um.meta_value LIKE ‘%searched_string%’
    OR um.meta_key = ‘last_name’
    AND um.meta_value LIKE ‘%searched_string%’

    This gives me the list of parents, no problem neither.

    Now I need to get the students related to these parents, and I don’t know how to do because parents id are stored into post_meta table, like this :

    a:2:{i:0;s:1:”4″;i:1;s:1:”6″;}

    Here the students has 2 related parents, of IDs 4 and 6.
    I have no way to do something like :

    SELECT * FROM wp_posts WHERE
    post_status LIKE ‘publish’
    AND post_type LIKE ‘student’
    AND post_title LIKE ‘%$searched_string’
    OR parent_id IN (4, 3)

    In this example I could get parents IDs with query 2, and then construct query 1 to say that student’s parents ID have to be one of the IDs found.

    I don’t know if I’m clear but what I know is I’m stuck.

    Any idea of how I could achive that ?

    Thanks a lot.

  • Unread

    Trying to sort Custom Post with date (date picker) for simple event display

    Hey guys, I feel like I’ve tried everything and I can’t get my WP_Query to sort by date that is selected via date picker. I have read the documentation on the Date Picker and looked at multiple 3rd party tutorials and I know I’m close. I am hoping someone here will be able to spot my error.

    In this example I am just trying to display the next scheduled event. I do not have an end date or end time because I don’t need one and want to keep the admin as simple as possible.. Everything is displaying the way I want it, it’s just not showing the next post based on date.

    Here is my code so far:

    <?php
    $today = current_time('Ymd');								
    
    	$args = array(
    		'post_type' => 'upcoming',
    		'post_status' => 'publish',
    		'posts_per_page' => '1',
    		'meta_query' => array(
    		array(
    			'key' => 'date',
    			'compare' => '>=',
    			'value' => $today,
    		)
    		),
    		'meta_key' => 'date',
    		'orderby' => 'meta_key',
    			'order' => 'ASC',
    		'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    	);
    	$query = new WP_Query($args);
    	if ($query->have_posts()) :
    	while ($query->have_posts()) : $query->the_post(); 
    ?>
    	<div class="next-class">
    		
    		<div class="next-cal-date">
    		 <?php
    			$date = DateTime::createFromFormat('d/m/Y', get_field('date'));
    			$time = DateTime::createFromFormat('g:i a', get_field('time'));
    		 ?>
    			<div class="topic-header"><?php echo $date->format('D') ?></div>
    			<div class="time"><?php echo $time->format('g:i') ?><div class="ampm"><?php echo $time->format('a') ?> C.S.T.</div></div>
    		</div>
    		
    		<div class="topic-header">CLASS</div>
    		<div class="class-title">
    		<?php
    		$terms = get_the_terms( $post->ID , 'class' );
    		foreach ( $terms as $term ) {
    		echo $term->name;
    		} ?>
    		<div class="clearfix"></div>
    		</div>
    		<div class="class-topic">
    		<div class="class-topic-lead">
    		Topic:
    		</div>
    			<?php the_title(); ?>
    		</div>
    		<div id="getting-started"></div>
    		<script type="text/javascript">
    		  jQuery("#getting-started")
    		  .countdown("<?php echo $date->format('Y/m/d'); echo " "; echo $time->format('g:i a') ?>", function(event) {  
    			jQuery(this).text(
    			  event.strftime('%D days %H:%M:%S')
    			);
    		  });
    		</script>
    	</div>
    	<?php endwhile; ?>
    	<?php else : ?>
    		Next Class Not Available
    
    	<?php endif; ?>
    <?php wp_reset_postdata(); ?>
    

    If you guys can spot my error I would be very thankful..

  • Helping

    Call get field in the function.php

    Hi,
    I have create a description field and i want to call this in the header with this code :

    
    // meta description 
    
    function wpse_custom_meta_description() 
    {
    
        if ( ! is_single() )
            return;
    
        $desc = get_field('meta_description');
    
        // Output
        if( ! empty( $desc ) )
            printf( 
                '<meta name="description" content="%s" />',
                esc_attr( trim( $desc ) )
            );
    }
    add_action( 'wp_head', 'wpse_custom_meta_description' , 2 );
    
     // meta description 
    

    But $desc is umpty !
    Who to do ? Thankyou

  • Helping

    Suddenly none of my fields are showing in frontend

    Hi All,

    I’m having a sudden problem where none of my image fields are showing anymore.

    They were showing with this setup for years, but now are coming up blank. I’m on WordPress 4.9.8 at this time.

    Anyway, please see my screenshot for how my image field is set up. I’m using an array.

    The code in my content-single.php file is:

    <?php if(get_field('_abk_photo')): ?>
    	<a class="acf_main_image" href="<?php $image = get_field('_abk_photo', $post_id ); echo($image['sizes']['large']); ?>" rel="lightbox" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'rt_myriad_wp' ), the_title_attribute( 'echo=0' ) ) ); ?>"><img class="product_imgabk" src="<?php $image = get_field('_abk_photo', $post_id ); echo($image['sizes']['medium']); ?>" alt="" /></a>
    	<?php else : ?>
    		<img src="../../../../uploads/2012/11/Product-Page-btn-spacer.png" alt="" />
    	<?php endif; ?>

    The code that is now output instead of the image is:

    <a class="acf_main_image" href="7" rel="lightbox" title="Permalink to Post Title"><img class="product_imgabk" src="7" alt=""></a>
    	<img class="product_imgabk" src="7" alt="">
    </a>

    Can anyone tell what the heck is going on here?

  • Helping

    jquery dynamically show acf field * quantity= total

    Hello programmers
    please help me I am a beginner with wordpress and really have a llot of time trying to fix this ..

    I am useing WordPress 4.9.8 Woocommerce 3.4.5 divi premium theme ACF plugin pro 5 latest update and every thing well updated ..

    I have a new shop project i have purchased the ACF 5 plugin pro i make acf number field as a Product points value custom field , its the number of product value points (pv) that my project need to be showin with the total summary .. means :- product quantity * product price = total price product quantity * pv = total product pv

    i want to show product acf number field (pv) times selected quantity on woocommecre product page like this:-

    jquery total calculate

    This is my acf number field :

    showing the custom field workout with me :

    
    <?php
    
    // ADDING PV TO PRODUCT SINGLE PAGE 
    add_action( 'woocommerce_single_product_summary', 'my_pv_value', 25,2 );
    
    function my_pv_value() {
      echo '<b>PV:</b> ' . get_field('pv');
      // Note: 'PV' is the slug of the ACF
    }

    and this is the local generated php for the acf number field (pv) file from acf pro tools :

    <?php
    // pv field php generated file :
    if( function_exists('acf_add_local_field_group') ):
    
        acf_add_local_field_group(array(
            'key' => 'group_5b9a18dd07cd3',
            'title' => 'pv',
            'fields' => array(
                array(
                    'key' => 'field_5b9a2d23996d4',
                    'label' => 'pv',
                    'name' => 'pv',
                    'type' => 'number',
                    'instructions' => 'pv value',
                    'required' => 1,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => 'pv',
                        'id' => '',
                    ),
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'min' => 0,
                    'max' => 100,
                    'step' => 1,
                ),
            ),
            'location' => array(
                array(
                    array(
                        'param' => 'post_type',
                        'operator' => '==',
                        'value' => 'product',
                    ),
                ),
            ),
            'menu_order' => 0,
            'position' => 'normal',
            'style' => 'default',
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'hide_on_screen' => '',
            'active' => 1,
            'description' => 'pv value',
        ));
    
        endif;

    how to modify this code snippt to do the same jop as price * qty in woocommerce_single_product_summary ?

    <?php
    // dynamic changer for total value this is a demo for the code final jquery  http://reigelgallarde.me/programming/show-product-price-times-selected-quantity-on-woocommecre-product-page/
    
    <?php
    add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
    function woocommerce_total_product_price() {
        global $woocommerce, $product;
        // let's setup our divs
        echo sprintf('<div id="product_total_price" style="margin-bottom:20px;">%s %s</div>',__('Product Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
        ?>
            <script>
                jQuery(function($){
                    var price = <?php echo $product->get_price(); ?>,
                        currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
    
                    $('[name=quantity]').change(function(){
                        if (!(this.value < 1)) {
    
                            var product_total = parseFloat(price * this.value);
    
                            $('#product_total_price .price').html( currency + product_total.toFixed(2));
    
                        }
                    });
                });
            </script>
        <?php
    }

    i am really confused and tired after two weeks of heavy docmentaion reading for acf pro and wp and woocommerce and allot of plugings and blogs and snippets and tutorials … etc

    please help me >>>>

    and i will be really happy if i manged how to but the generated pv total results in cart page as pv total but not related to total money because total its only calculate of product points value not the price*qty

    and how to but it in checkout page too.

    i am in need for this fix so i can move to my project other things

    i am really appreciate your help.

  • Unread

    How to get the previous and next post ID when posts are sorted by custom field?

    It is sort of a follow up question to the following issue. Basically a page where a date time field was attached to the post post type and then posts got sorted by that field with the constraint that only posts aka events today or in the future should be shown. In the other issue I’ve asked and afterwards described how I solved modifying the custom loop the Phlox theme the page is using by pre_get_posts. But the real nasty problems turned up when I noticed the previous and next links in the single post view. They were totally out of sort as well as showing also past events. I’ve learned then that the previous and next buttons utilize their own queries and by default refer also just to the main query. But by the aid of the get_adjacent_post filters I was able to get my posts sorted again as well as only show todays as well as future posts by using:

    function mv_adjacent_post_join() {
        global $wpdb;
        return "INNER JOIN $wpdb->postmeta AS mvpm ON mvpm.post_id = p.ID";
    }
    add_filter( 'get_previous_post_join', 'mv_adjacent_post_join' );
    add_filter( 'get_next_post_join', 'mv_adjacent_post_join' );
    
    function mv_previous_post_where() {
        global $wpdb, $post;
        $mv_event_start = date( 'Y-m-d H:i:s', strtotime( '-8 hours' ) );
        return $wpdb->prepare( " WHERE mvpm.meta_key = 'event_start' AND CAST(mvpm.meta_value AS DATETIME) >= %s AND p.post_type = 'post' AND p.post_status = 'publish'", $mv_event_start );
    }
    add_filter( 'get_previous_post_where', 'mv_previous_post_where' );
    
    function mv_next_post_where() {
        global $wpdb, $post;
        $mv_event_start = date( 'Y-m-d H:i:s', strtotime( '-8 hours' ) );
        return $wpdb->prepare(" WHERE mvpm.meta_key = 'event_start' AND CAST(mvpm.meta_value AS DATETIME) >= %s AND p.post_type = 'post' AND p.post_status = 'publish'", $mv_event_start );
    }
    add_filter( 'get_next_post_where', 'mv_next_post_where' );
    
    function mv_previous_post_sort() {
        return "ORDER BY mvpm.meta_value DESC LIMIT 1";
    }
    add_filter( 'get_previous_post_sort', 'mv_previous_post_sort' );
    
    function mv_next_post_sort() {
        return "ORDER BY mvpm.meta_value ASC LIMIT 1";
    }
    add_filter( 'get_next_post_sort', 'mv_next_post_sort' );

    The only problem left get_adjecant_postsdoesn’t really know what the next and previous post is each time. :/ In wp-includes/link-template.php it is accomplished by comparing p.post_date with $post->post_datebut for me those two look basically the same. But in my case i would need to compare the event_startdate time field of the current post to the date and time of the previous and next post within the WHERE filter? But how do I determine the ID of the next and previous post easily and apply it to the line of SQL in the WHERE filter?

  • Helping

    shortcode with parameters for repeater field

    I am using ACF repeater field for making a custom menu, so I can use different menu’s on each product description page. I have added a options page to allow the user add details from the dashboard. Screenshot here.
    ACF repeter field, options page

    I have a image field, a nav menu, for which I am using this plugin(https://github.com/jgraup/advanced-custom-fields-nav-menu-field) and a couple of more fields.

    I am looking for a solution to have a short-code to spit out only one row out of the list something like [custom_menu-1] for the first one. (OR should I use 0 since the repeater array starts with 0?)

    This is what I am currently using to display a preview on the dashboard.

    	/**
    	 *  Display custom content after an ACF settings page
    	 *
    	 *  @since 1.0.0
    	 */
    	public function after_acf_options_page()
    	{
    		if( have_rows( 'repeter_field_name', 'option' ) ) :
    
    			while( have_rows( 'new_local_menu', 'option' ) ) :
    
    			the_row(); ?>
    
    				<nav id="localnav" class="js no-touch css-sticky" lang="en-US" dir="ltr" data-sticky="" data-analytics-region="local nav" role="navigation">
    
    					<div class="ln-wrapper">
    
    						<div class="ln-background"></div>
    
    						<div class="ln-content">
    
    							<div class="ln-title">
    
    								<?php if( '' !== get_sub_field( 'logo' ) ) : 
    								$secondary_logo = get_sub_field('logo');
    									if (!empty($logo)) {
    										printf( '<a href="%s" data-analytics-title="secondary logo"><img alt="logo" src="%s" height="50px"/></a>',
    										get_sub_field( 'logo_hyperlink' ),
    										get_sub_field( 'logo' )
    									);
    										   }
    										   ?>
    
    								<?php endif; ?>
    
    							</div><!-- /.ln-title -->
    
    							<div class="ln-menu">
    
    								<a href="#ln-menustate" class="ln-menucta-anchor ln-menucta-anchor-open" id="ln-menustate-open">
    									<span class="ln-menucta-anchor-label">Open menu</span>
    								</a>
    								<a href="#" class="ln-menucta-anchor ln-menucta-anchor-close" id="ln-menustate-close">
    									<span class="ln-menucta-anchor-label">Close menu</span>
    								</a>
    
    								<?php the_sub_field( 'select_nav_menu' ); ?>
    
    								<?php if( '' !== get_sub_field( 'call_to_action' ) ) : ?>
    
    									<div class="ln-action ln-action-button">
    										<?php printf( '<a class="ln-button" href="%s" data-analytics-title="button">%s <span class="ln-action-product"></span></a>',
    											esc_url( get_sub_field( 'call_to_action' ) ),
    											__( 'Buy' )
    										); ?>
    									</div><!-- /.ln-action-button-->
    
    								<?php endif; ?>
    
    							</div><!-- /.ln-menu -->
    
    						</div><!-- /.ln-content -->
    
    					</div><!-- /.ln-wrapper -->
    
    				</nav><!-- /#localnav -->
    
    			<?php endwhile;
    
    		endif;
    	}

    Obviously, it display all the rows that are added so far. How do I identify each row? I read that each repeater field row had an id starting with 0, like an array. Assuming that I can use that to identify which row to display. I am not sure what should I change in my code to do so.

    I read a few other articles and topics here, but most of them are use to display all the rows.
    Can someone please help me with this.

  • Unread

    Custom Google maps pin when calling a field group in the frontend

    I am trying to figure how can I replace default Google pin when I call ACF field group directly in my page.php. (somewhat close to the case described here) Here is the source I use to call the group:

                    <?php
    
                    acf_form(array(
                        'post_id'		=> 'new_post',
                        'field_groups'  => array( 72 ),
                        'new_post'		=> array(
                            'post_type'	=> 'post',
                            'post_status'	=> 'publish',
                        ),
                        'submit_value'          => '[+] Send',
                        'return'                => '/',
                        'html_submit_button'    =>  '<input type="submit" id="addsignal" value="%s" />'
                    ));
    
                    ?>

    Since I could not figure out how to pass the new pin icon to the Google Maps field with this syntax, I presume there might be something I can add to functions.php that will do the trick? I already tried what was described in the linked topic but with no result. For what it’s worth, I am not using the PRO version.

  • Solved

    I have problem with pagination

    Hi, I’m a newbie for WordPress. I’m having problems. The code below

    <?php
    /**
     * The template for displaying search results pages.
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
     *
     * @package storeone
     */
    get_header();
    ?>
    <div class="container-fluid bgs-space bgs-blog">
    	<div class="container">
    		<div class="row">
    			<div class="col-md-9 col-sm-9 col-xs-12 bgs-blog-right">
    				<?php 
    					$args = apply_filters(
    						'acf/fields/post_object/query/',
    						get_search_query(),
    						isset($_GET['topic_type']) ? $_GET['topic_type'] : null, 
    						isset($_GET['real_estate_type']) ? $_GET['real_estate_type'] : null, 
    						isset($_GET['no_of_room']) ? $_GET['no_of_room'] : null, 
    						isset($_GET['no_of_bath_room']) ? $_GET['no_of_bath_room'] : null,
    						isset($_GET['minp']) ? $_GET['minp'] : null, 
    						isset($_GET['maxp']) ? $_GET['maxp'] : null);
    					$get_posts = new WP_Query( $args );
    				?>
    					<?php
    					if ( $get_posts->have_posts() ) : ?>
    
    						<div class="page-header">
    							<h1 class="page-title"><?php printf( esc_html__( 'Search Results for: %s', 'storeone' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    						</div><!-- .page-header -->
    
    						<div id="bgs-blog-content" class="row blog-gallery bgs-posts search-result">
    						<?php
    						/* Start the Loop */
    						while ( $get_posts->have_posts() ) : $get_posts->the_post();
    
    							/**
    							 * Run the loop for the search to output the results.
    							 * If you want to overload this in a child theme then include a file
    							 * called content-search.php and that will be used instead.
    							 */
    							get_template_part( 'template-parts/content', 'search' );
    
    						endwhile;
    						?>
    						</div>
    						<div class="row bgs-pagination">
    							<?php the_posts_pagination();?>
    						</div>
    						<?php
    					else :
    						wp_reset_query();
    						get_template_part( 'template-parts/content', 'none' );
    
    					endif; ?>
    			</div>
    			<?php get_sidebar(); ?>
    		</div>
    	</div>
    </div>
    <?php
    get_footer();

    It display great results, but the pagination bar does not display.
    Thanks for the help.

  • Unread

    Difficulty displaying the taxonomy name in acf

    Hey everyone, I’m having a hard time displaying the name of the tags using term-> name. Just show the example id: 3985. What am I doing wrong. I wanted something like: John to appear instead of id 3985. Here is the example I’m trying to unsuccessfully. :

    if ( have_rows( 'criticareview' ) ):
        while ( have_rows( 'criticareview' ) ): the_row();
          $content .= sprintf( <meta itemprop="name" content="%s" />
                <meta itemprop="sameAs" content="%s" />, 
    $terms = get_sub_field('directorcollections', $taxonomy, $term->name),
              
              get_term_link(get_sub_field('directorcollections'));

    The get_term_link part is working correctly. My problem is in the part of displaying the term-> name that only appears the ID. Someone could show the way to this solution. I have tried many things without success.
    Thanks for the help =).

  • Solved

    Field repeater with shortcode better coding

    Hey everyone, I’m developing a review session. However, I got the way to pull the content layout of the repeater field as in the code below. It works fine. My question is if there is any way to better code the code that I am putting here for your analysis. I’m using shortcode. If you wish to use this function to use your repeater, please feel free to do so.

    function cine_acf_shortcode (  ) {
        
    if ( have_rows( 'criticareview' ) ):
        while ( have_rows( 'criticareview' ) ): the_row();
          $content .= sprintf('<div class="py-1">
        <div class="container-1">
          <div class="row">');
          $content .= sprintf( '
           <div itemscope="" itemtype="http://schema.org/Review" id="review" class="review-cinefilosgamer">
    
          <div class="row">
            <div class="col-md-4">
              <h2 class="display-1 text-secondary">%s</h2></div>', get_sub_field( 'textnotes' ));
          $content .= sprintf( '<div class="col-md-4">
              <h3 class="">%s</h3><p class="lead text-center">%s</p></div>', get_the_title(), get_sub_field('reviewstars') );
    
          $content .= sprintf( '<div class="col-md-4">
              <p class="lead text-center">%s</p>', get_sub_field( 'reviewnumber') );
          $content .= sprintf( '<p class="lead text-center">%s</p>', get_sub_field('reviewquality'));
          $content .= sprintf('<p class="lead text-center">por <a href="%s">%s</a></p>
            </div>
          </div>', get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ), get_sub_field('revnauser'));
           $content .= sprintf('<div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-4"></div>
            <div class="col-md-4"></div>
          </div>
        </div>
    </div>'); 
     
        endwhile;
      endif;
      return $content;
    
    } 
    
     
    add_shortcode( 'acfcine', 'cine_acf_shortcode',1 );
    
  • Helping

    acf_form() and AJAX

    Hi

    I have been trying to call acf_form() in front end through AJAX. I have finally managed to get Edit to work flawlessly, but have some problems with inserting a new post. Whenever I insert a new post, whatever I enter will be stored in wp_option table and used as default for the next new post. Here’s portions of my code I thought would be relevant.

    JavaScript to get the form and submit it back:

    function newPost(contentType) {
        document.getElementById(contentType + "_holder").innerHTML = "<div class='ajaxloading'>&nbsp;</div>";
        jQuery(document).ready(function($) {
                    var data = {
                        action: 'new_post',
                        post_type: contentType,
                        security : MyAjax.security,
                    };
                    $.post(MyAjax.ajaxurl, data, function(response) {
                        document.getElementById(contentType + "_holder").innerHTML = response;
                        initACF(contentType);
                    });
                });
        return false;
    }
    
    function initACF(contentType) {
         $(document).trigger('acf/setup_fields', [
            $('#poststuff')
          ])
        $('.acf-form').on('submit', (event) => {
            event.preventDefault();
            
            var form_data = {'action' : 'acf/validate_save_post', 'post_type': contentType};
            jQuery('.acf-form :input').each(function() {
                form_data[jQuery(this).attr('name')] = jQuery(this).val();
            })
            
            form_data.action = 'save_my_data';
            $('html,body').css('cursor', 'wait');
            jQuery.post(MyAjax.ajaxurl, form_data).done(function(save_data) {
                $('html,body').css('cursor', 'default');
                getContent(contentType);
            })
        });
    }
    

    php code to call acf_form and send it back to the ajax request:

    function new_post_callback() {
        check_ajax_referer('my-special-string', 'security');
        switch ($_POST['post_type']) {
            case "contacts":
                $field_group = 80;
                break;
            case "vacations":
                $field_group = 103;
                break;
            case "messages":
                $field_group = 84;
                break;
            default:
                wp_die();
        }
        $settings = array(
            'id' => 'acf-form',
            'post_id' => 'new_post',
            'new_post' => array('post_type' => $_POST['post_type']),
            'return' => '',
            'field_groups'=>array($field_group),
            'html_before_fields' => '',
            'html_after_fields' => '',
            'submit_value' => __("Insert", 'acf'),
            'updated_message' => __("Post inserted", 'acf'),
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'honeypot' => true,
            'html_submit_button'	=> '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
            'kses'	=> false
    	);
        acf_form($settings);
        wp_die();
    }
    
    add_action('wp_ajax_new_post', 'new_post_callback');

    And here’s the code which saves new posts:

    function my_acf_save_post($post_id) {
    	if ($post_id !== 'new_post') {
    		return $post_id;
    	}
    	
    	$post = array(
    	            'post_status' => 'private',
    	            'post_type' => $_POST['post_type']);
    	switch ($_POST['post_type']) {
    	    case 'contacts':
    	        $fields = array('name'=>$_POST['fields'][NAME_FIELD], 'email'=>$_POST['fields'][EMAIL_FIELD]);
    	        break;
    	    case 'vacations':
    	        $fields = array('date_from'=>$_POST['fields'][DATE_FROM_FIELD], 'date_to'=>$_POST['fields'][DATE_TO_FIELD]);
    	        break;
    	    case 'messages':
    	        $fields = array('subject'=>$_POST['fields'][SUBJECT_FIELD], 'receipients'=>$_POST['fields'][RECEIPIENTS_FIELD], 'message'=>$_POST['fields'][MESSAGE_FIELD], 'release_in'=>$_POST[RELEASE_IN_FIELD]);
    	        break;
    	    default:
    	        return $post_id;
    	}
    	
    	$post_id = wp_insert_post($post);
    	foreach ($fields as $key => $value) {
    	    update_field($key, $value, $post_id);
    	}
    	
    	return $post_id;
    }

    Of interest is, I need to call this only for new posts, as edits work perfectly by simply using acf_form_head() as the ajax action.

    I would really appreciate any help. I tried to post this on wordpress.stackexchange.com but people there didn’t really think much of it and started down voting :'(

  • Helping

    Meta Title Incorrect for a Custom Permalink Structure

    By redirecting a 404 page, we were able to get a custom permalink structure with /%service%/%area%/listingname to work with ACF custom posts. Everything is correct except ONE item… the Meta Title displays the title of the latest blog post.

    I can’t figure out how to fix this. I’ve included the code for the custom permalink structure below. Can someone provide some insight to getting the title to be correct?

    add_action('template_redirect', 'flex_advanced_cpt_permalink_structure');
    function flex_advanced_cpt_permalink_structure()
    {
        if (is_404()) {
    
            global $wp_query;
            $service_index = 1;
            $area_index = 2;
            $service_tax = "services";
            $area_tax = "areas";
            $post_type = 'listing';
    
            $url = array_filter(explode('/', $_SERVER['REQUEST_URI']));
    
            if (count($url) == 1) {
                if (term_exists($url[$service_index], $service_tax)) {
    
                    $wp_query = new WP_Query(array(
                        'post_type' => $post_type,
                        'tax_query' => array(
                            'relation' => 'AND',
                            array(
                                'taxonomy' => $service_tax,
                                'field' => 'slug',
                                'terms' => $url[$service_index],
                            ),
                        ),
                    ));
                    status_header(200);
                    include('/public_html/wp-content/themes/genesis/index.php');
                    exit();
                }else if(term_exists($url[$service_index], $area_tax)){
                    $wp_query = new WP_Query(array(
                        'post_type' => $post_type,
                        'tax_query' => array(
                            'relation' => 'AND',
                            array(
                                'taxonomy' => $area_tax,
                                'field' => 'slug',
                                'terms' => $url[$service_index],
                            ),
                        ),
                    ));
                    status_header(200);
                    include('/public_html/wp-content/themes/genesis/index.php');
                    exit();
                }
            } else if ((count($url) == 2)) {
                if (term_exists($url[$service_index], $service_tax) && term_exists($url[$area_index], $area_tax)) {
    
                    $wp_query = new WP_Query(array(
                        'post_type' => $post_type,
                        'tax_query' => array(
                            'relation' => 'AND',
                            array(
                                'taxonomy' => $service_tax,
                                'field' => 'slug',
                                'terms' => $url[$service_index],
                            ),
                            array(
                                'taxonomy' => $area_tax,
                                'field' => 'slug',
                                'terms' => $url[$area_index],
                            ),
                        ),
                    ));
                    status_header(200);
                    include('/public_html/wp-content/themes/genesis/index.php');
                    exit();
    
                }
            } else if (count($url) == 3) {
                if (term_exists($url[$service_index], $service_tax) && term_exists($url[$area_index], $area_tax)) {
                    $wp_query = new WP_Query(array(
                        'post_type' => $post_type,
                        'name' => $url[3],
                        'tax_query' => array(
                            'relation' => 'AND',
                            array(
                                'taxonomy' => $service_tax,
                                'field' => 'slug',
                                'terms' => $url[$service_index],
                            ),
                            array(
                                'taxonomy' => $area_tax,
                                'field' => 'slug',
                                'terms' => $url[$area_index],
                            ),
                        ),
                    ));
                    status_header(200);
                    include('/public_html/wp-content/themes/dynamik-gen/single-listing.php');
                    exit();
    
                }
            }
    
        }
    
    }
    
    add_filter('post_type_link', 'pleasure_post_links', 99, 2);
    function pleasure_post_links($permalink, $post)
    {
    
        if ($post->post_type == "listing") {
            $service = wp_get_post_terms($post->ID, 'services');
            $area = wp_get_post_terms($post->ID, 'areas');
    
            $permalink = get_bloginfo('url') . '/' . $service[0]->slug . '/' . $area[0]->slug . '/' . $post->post_name;
            return $permalink;
        }
        return $permalink;
  • Helping

    Populate acf_form title with taxonomy term value

    Hi,

    I have a basic front end form set up with a selected field group that saves it’s data into a custom post type, nothing too complicated. However, I’m having an issue generating a post title from a taxonomy term.

    Basically, the user can select one term value from a dropdown select list on the form (as well as fill out other fields), then submit the form. I want the post title to reflect the string value of the term, but instead it’s just returning the term ID.

    Here’s my code:

    functions.php

    
    function my_save_post( $post_id ) {
    	
      if ($post_type != 'points') {
        return;
      }
    	
      $taxonomy = $_POST['acf']['field_59940ffa4a644'];
    
      $title = $taxonomy;
    
      $new_post = array(
        'ID'           => $post_id,
        'post_status' => 'publish',
        'post_title' => $title,
        'post_type' => 'points'
      );
    
      remove_action('acf/save_post', 'my_save_post', 20);
      wp_update_post( $new_post );
      add_action('acf/save_post', 'my_save_post', 20);
    
    }
    
    add_action('acf/save_post', 'my_save_post', 20);
    

    page-template.php

    
    acf_form(
      array(
        'id' => 'form-points',
        'post_id' => 'new_post',
        'field_groups' => array(126),
        'html_submit_button'	=> '<input type="submit" class="btn btn-samurai" value="%s" />',      
        'submit_value' => 'Submit Points',
        'updated_message' => 'Points Created Successfully'
      ) 
    ); 
    

    To recap… the form works, but it saves the title of the post as an integer value (the term ID perhaps?), rather than the actual term string value.

    Any help would be awesome, thanks in advance!

  • Unread

    How to change order with next and previous button

    Hi,
    I have a problem to order single post by a custom field when I navigate with prev and next button. I have a code to change the order by title which works, but I can’t figure out how to use a custom field instead. Is there a way to do it ?

    Here is my code in my single.php

    <?php
    	function mytheme_previous_post_orderby_name($orderby){
    	    return "ORDER BY p.post_title DESC LIMIT 1";
    	}
    	function mytheme_previous_post_where_name(){
    	    global $post, $wpdb;
    	    return $wpdb->prepare( "WHERE p.post_title < %s AND p.post_type = %s AND ( p.post_status = 'publish' OR p.post_status = 'private' )", $post->post_title, $post->post_type );
    	}
    	function mytheme_next_post_orderby_name($orderby){
    	    return "ORDER BY p.post_title ASC LIMIT 1";
    	}
    	function mytheme_next_post_where_name(){
    	    global $post, $wpdb;
    	    return $wpdb->prepare( "WHERE p.post_title > %s AND p.post_type = %s AND ( p.post_status = 'publish' OR p.post_status = 'private' )", $post->post_title, $post->post_type );
    	}
    	add_filter('get_previous_post_sort', 'mytheme_previous_post_orderby_name', 10, 1);
    	add_filter('get_next_post_sort', 'mytheme_next_post_orderby_name', 10, 1);
    
    	add_filter('get_previous_post_where', 'mytheme_previous_post_where_name', 10);
    	add_filter('get_next_post_where', 'mytheme_next_post_where_name', 10);
    ?>
    <div>
    	 <?php previous_post_link('%link', 'previous', TRUE); ?>
    	 <?php next_post_link('%link', 'next', TRUE); ?>
    </div>
    <?php
    	remove_filter('get_previous_post_sort', 'mytheme_previous_post_orderby_name', 10);
    	remove_filter('get_next_post_sort', 'mytheme_next_post_orderby_name', 10);
    	remove_filter('get_previous_post_where', 'mytheme_previous_post_where_name', 10);
    	remove_filter('get_next_post_where', 'mytheme_next_post_where_name', 10);
    ?>

    I searched already, but I can’t find any solution to that problem,
    thanks !

  • Helping

    Assigning an Img Class in PHP

    Hello,

    I’ve created a function that gets the image ID from ACF then creates a background that changes by the day of the week. I’d like to load the images by lazyload but don’t know how to assign an image class with the function. Grateful for any suggestions.

    function my_custom_background() {
    
    	if ( ! is_front_page() ) {
    		return;
    	}
    
    	$img_id = get_field( strtolower( date( 'l' ) ) );
    
    	echo "<style>\n";
    
    	// Large desktops.
    	
    	$img = wp_get_attachment_image_src( $img_id, 'large_desktop_background' );
    	
    
    	echo "body {\n";
    	echo sprintf( "\tbackground-image: url(%s);\n", $img[0] );
    	echo "}\n";
    	
    
    	// Small desktops.
    	
    	
    	$img = wp_get_attachment_image_src( $img_id, 'small_desktop_background' );
    	
    	
    	echo "@media (max-width: 1199px) {\n";
    	echo "\tbody {\n";
    	echo sprintf( "\t\tbackground-image: url(%s);\n", $img[0] );
    	echo "\t}\n";
    	echo "}\n";
    
    	// Tablets.
    	
    	$img = wp_get_attachment_image_src( $img_id, 'tablet_background' );
    	
    	
    	echo "@media (max-width: 991px) {\n";
    	echo "\tbody {\n";
    	echo sprintf( "\t\tbackground-image: url(%s);\n", $img[0] );
    	echo "\t}\n";
    	echo "}\n";
    
    	// Mobile.
    	
    	$img = wp_get_attachment_image_src( $img_id, 'phone_background' );
    
    	echo "@media (max-width: 767px) {\n";
    	echo "\tbody {\n";
    	echo sprintf( "\t\tbackground-image: url(%s);\n", $img[0] );
    	echo "\t}\n";
    	echo "}\n";
    
    	echo "</style>\n";
    
    }
    add_action( 'wp_head', 'my_custom_background' );
    
  • Solving

    Retreiving repeters subfields values from database

    Hi,
    I’m trying to retreive repeter subfields values using DB queries and get_field_object() for a client of mine who wants to keep fields contents as raw content in post_content.
    My repeter field is jst_iconbox and my subfield is iconbox_content.

    I’ve created 3 iconbox fields on admin page and i’m quering the DB like this :

    global $wpdb;
    $prefix =$wpdb->prefix;
    $tablename = $prefix."postmeta";
    $sql = "SELECT * FROM {$tablename} WHERE meta_key LIKE %s GROUP BY meta_key";
    $iconbox_contents = $wpdb->get_results( $wpdb->prepare( $sql, '_jst_iconbox_%_iconbox_content' ) );

    But while i’m looping through my result i have no value foreach field found :

    foreach( $iconbox_contents as $boxcontent )
    {
    	$field =  get_field_object( $boxcontent->meta_value, get_the_ID() );
    	echo '<pre>'.print_r( $field, 1) .'</pre><hr>';
    }

    … prints 3 times somting like :

    
        [ID] => 1825
        [key] => field_59d4a5496ec7d
        [label] => JsT Iconbox Content
        [name] => jst_iconbox_content
        [prefix] => acf
        [type] => wysiwyg
        [value] => 
        [menu_order] => 0

    I must have missanderstood something …
    Any idea ?

    Thank’s

Viewing 25 results - 51 through 75 (of 281 total)