Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • well, that’s because I missed something extremely important

    
      while ($the_query->have_posts()) {
        $the_query->the_post(); // this is missing
        // get state and compare it to the previous post
    
  • what kind of field is ‘facebook_group_name’ agian?
    Then that shouldn’t be it.

    What happens when you do this?

    
    $args = array(
      'post_type' => 'locations',
      'posts_per_page' => -1
    );
    $query = new WP_Query($args);
    $facebook_ids = array();
    if ($query->have_posts()) {
      while($query->have_post()) {
        $query->the_post();
        echo get_field('facebook_group_name').'<br />';
        $facebook_ids[] = get_field('facebook_group_name');
      }
      wp_reset_postdata();
    }
    echo implode(',', $facebook_ids);
    
  • Where is this code running? In a template, or in a function.

    try adding

    
    if ($query->have_posts()) {
      global $post; // try adding this here
      while($query->have_post()) {
    
  • So then this query should return 3 posts

    
    $args = array(
      'post_type' => 'locations',
      'posts_per_page' => -1
    );
    $query = new WP_Query($args);
    
    // output posts to see if they are returned by the query
    echo '<pre>'; print_r($query->posts); echo '</pre>';
    
  • Is the post type slug correct? 'post_type' => 'locations' Either the query is not returning any posts or there are no values stored for that field name.

  • sorry about the typos, what are the results of this, anything?

    
    $args = array(
      'post_type' => 'locations',
      'posts_per_page' => -1
    );
    $query = new WP_Query($args);
    $facebook_ids = array();
    if ($query->have_posts()) {
      while($query->have_post()) {
        $query->the_post();
        $facebook_ids[] = get_field('facebook_group_name');
      }
      wp_reset_postdata();
    }
    echo implode(',', $facebook_ids);
    
  • Nope. This didn’t solve it (and there were some missing closing semi-colons).

    I also tried with “explode” instead of “implode” and it didn’t work.

    Here’s my current code:

    $args = array(
      'post_type' => 'locations',
      'posts_per_page' => -1
    );
    $query = new WP_Query($args);
    $facebook_ids = array();
    if ($query->have_posts()) {
      while($query->have_post()) {
        $query->the_post();
        $facebook_ids[] = get_field('facebook_group_name');
      }
      wp_reset_postdata();
    }
    echo explode(',', $facebook_ids);
  • hi @mathieu and @jdaquila
    same problem for me. Have you solved in some way?

  • @exove you could put this in your header:

    
    if (get_field('location')) :
      wp_enqueue_script('...');
    endif;
    

    …where location is the name of your field

  • i’m using the below code to add a custom meta
    where organizer_gender is radio button,
    organizer_certification is text,
    city is multiple checkbox.

    i have only one problem, the city is always coming first not in sequence.

    function custom_content_filter_the_content( $content ) {     
        if ( is_singular( 'tribe_organizer' ) && function_exists('get_field') ) {   
         $content .= get_the_title();
         $content .=  ' is trainer for ' . get_field('organizer_gender') . ' gender ' ;
         $content .= ' certified: ' . get_field('organizer_certification');
         $content .= ' located in ' . the_field('city') . '';
         $content .=  ' Find contact details.' ;
        }
         return $content;
    }
    
    function hook_meta() {
    ?>
    <meta name="description" content="<?php echo strip_tags(custom_content_filter_the_content()); ?>" />
    <meta property="og:description" content="<?php echo strip_tags(custom_content_filter_the_content()); ?>" />
    <meta name="twitter:description" content="<?php echo strip_tags(custom_content_filter_the_content()); ?>" />
    <?php
    }
    add_action('wp_head', 'hook_meta');
  • Could you create a search like that with the aid of ACF? Yes. Is it something that will be easy to do? Likely not. You would need to build the entire search UI yourself and make it submit the search.

    For an idea of what you’ll be getting into when getting the search results check the Dynamic $_GET parameters section of this page https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ and this giuide https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/

    As far as the UI, you’d be mostly on your own.

  • With some help from the guys on the WP forum I managed to get this working. I have shared the code below incase anybody needs it in the future.

    <?php
    $field = get_field('CUSTOM_FIELD');
    if ($field) {
      $file = $_SERVER['DOCUMENT_ROOT'] . '/files/' . $field . '.php';
      require_once( $file);
    }
    ?>
  • I’ve been working with this same code, but to filter “Coupons” by “Service Type”, where service_type is a custom post type that is part of each coupon in the form of a relationship field. The one thing that i did that made this work is to add:

    $query->query_vars['meta_compare'] = 'LIKE';

    in the wpse45436_posts_filter function so it should read like this:

    function wpse45436_posts_filter( $query ){
        global $pagenow;
        $type = 'post';
        if (isset($_GET['post_type'])) {
            $type = $_GET['post_type'];
        }
        if ( 'sp_people' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') {
            $query->query_vars['meta_key']     = 'sp_people_status';
            $query->query_vars['meta_value']   = $_GET['ADMIN_FILTER_FIELD_VALUE'];
            $query->query_vars['meta_compare'] = 'LIKE';
        }
    }

    Hope this works for you.

  • Something like:

    
    <div class="show-on-desktop hide">
      Visible on Desktop
    </div>
    
    <div class="show-on-mobile hide">
      Visible on Mobile
    </div>
    

    and then your JS would be:

    
    var windowWidth = $(window).width();
    var $desktopVisible = $('.show-on-desktop');
    var $mobileVisible = $('.show-on-mobile');
    
    if (windowWidth <= 640) {
      $desktopVisible.addClass('hide');
      $mobileVisible.removeClass('hide');
    } else {
      $desktopVisible.removeClass('hide');
      $mobileVisible.addClass('hide');
    }
    

    CSS:

    
    .hide {display:none;}
    

    Like so?

  • I’ve now got it working with the following code:

    <?php
        $terms = get_the_terms( get_the_ID(), 'product_brands' );
    
           if( ! empty( $terms ) ) : ?>
               <ul>	
    		<?php foreach( $terms as $term ) : ?>
    						    	 
    		 <li class="<?php echo $term->slug; ?>">
    															
                        <img src="<?php the_field('brand_logo', $term); ?>" />
    		  
                     </li>
    
      <?php endforeach; ?>
              </ul> 
    <?php
       endif;
    ?>

    I had to change the taxonomy name from brands to product_brands because I was already using a brands taxonomy for another CPT. However, this wasn’t the cause of the images not displaying, the only thing that was missing before was wrapping the <?php the_field(‘brand_logo’, $term); ?> in an image tag, seems obvious now.

    Are there any issues doing it this way?.

  • I’ll try. But I’m repeating my self here. But maybe this will clarify.

    This is my ACF form:

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php acf_form(array(
                    'post_id'       => 'new_post',
                    'new_post'      => array(
                        'post_type'     => 'db_test',
                        'post_status'       => 'publish'
                    ),
                    'submit_value'      => 'Create a new event',
                    // 'return' => '/wp-content/themes/MY_THEME/includes/new-employee.php'
                )); ?>
            <?php endwhile; ?>
        </div>
    </div>

    It gives me this HTML

    <form id="acf-form" class="acf-form" action="" method="post">
    	<div class="acf-fields acf-form-fields -top">
    		<div id="Firstname" class="acf-field acf-field-text acf-field-5968834df2ac1 voornaam" style="width:40%;" data-name="voornaam" data-type="text" data-key="field_5968834df2ac1" data-width="40">
    			<div class="acf-label">
    				<label for="acf-field_5968834df2ac1">Voornaam</label>
    			</div>
    			<div class="acf-input">
    				<div class="acf-input-wrap"><input type="text" id="acf-field_5968834df2ac1" class="" name="acf[field_5968834df2ac1]" value="" placeholder="" /></div>	</div>
    			</div>
    		</div>
    	<div class="acf-form-submit">
    		<input type="submit" class="acf-button button button-primary button-large" value="Create a new event" />			<span class="acf-spinner"></span>			
    	</div>
    </form>

    All I want is when you click on submit it writes the entry to the WP database and returns the value of this acf[field_5968834df2ac1] field using an echo.

    Im trying to do that using this code:

    <?php
        $FirstName = $_POST['acf']['field_5968834df2ac1'];
        echo 'data' . $FirstName; ?>

    But that doesn’t give me any results. So my question was/is how do I get the value of this field when I clicked on submit and the page reloads.

    Here is my whole code:

    <?php acf_form_head(); ?>
    <?php /* Template name: Nieuwe Collega's */ get_header(); ?>
    <?php session_start();
    $_SESSION['foo'] = $_POST['acf']['field_5968834df2ac1'];
    ?>
    
    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php acf_form(array(
                    'post_id'       => 'new_post',
                    'new_post'      => array(
                        'post_type'     => 'db_test',
                        'post_status'       => 'publish'
                    ),
                    'submit_value'      => 'Create a new event',
                    // 'return' => '/wp-content/themes/intranetpuur/includes/new-employee.php'
                )); ?>
            <?php endwhile; ?>
        </div>
    </div>
    <?php
        $FirstName = $_POST['acf']['field_5968834df2ac1'];
        echo 'data' . $FirstName;
        echo $_SESSION['foo'];
     ?>
    <?php get_footer(); ?>
  • this does not tell me anything

    I’m trying to echo the value when you press submit

    Please provide code that is specific to what you are attempting to do, whatever it is that you’re attempting to do. If this is an a filter that you are creating then the information on how you are adding the filter and the code of that filter would be helpful.

  • John,

    I understand have_rows() but that doesn’t answer my specific question. Are you saying that the returned records are in the order determined by the user using the drag-and-drop ordering?

  • Is your field set to return the URL? or the object?

    
    // ACF < 5.5.0
    <img src="<?php the_field('image_field_name', $custom_term->taxonomy.'_'.$ $custom_term->term_id); ?>" alt="" class="img-responsive">
    
    
    // ACF >= 5.5.0
    <img src="<?php the_field('image_field_name', 'term_'.$custom_term->term_id); ?>" alt="" class="img-responsive">
    

    See https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

    If you are returning a image object/array instead of the url then see https://www.advancedcustomfields.com/resources/image/ for information on showing image fields.

  • You need to query all of the locations posts, loop through them and get the values.

    
    $args = array(
      'post_type' => 'locations',
      'posts_per_page' => -1
    )
    $query = new WP_Query($args);
    $facebook_ids = array();
    if ($query->have_posts()) {
      while($query->have_post()) {
        $query->the_post();
        $facebook_ids[] = get_field('facebook_id');
      }
      wp_reset_postdata()
    }
    echo implode(',', $facebook_ids);
    
  • I cannot recreate your issue. I created a CPT and any user type that can edit the CPT can see the custom fields I add to it. You’re issue has to be something to do with something in another plugin or your theme.

    You need to figure out what you have that’s causing the issue by deactivating other plugins and narrow it down.

    As far as your other questions, I don’t know how to do any of those things.

  • Fixed. For past posts, the value is passed by this bulk action.

    add_filter( 'bulk_actions-edit-post', 'register_my_bulk_actions2' );
     function register_my_bulk_actions2($post_ids) {
        global $wpdb;
          $users = $wpdb->get_results( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'genere'AND meta_value = 'Maschio' " );
        foreach ( $users as $a ) {
            $author_ids[] = $a->user_id;
        }
    
       $args = array( 'posts_per_page' => -1 ,  'author__in' =>  $author_ids, );
       $myposts = get_posts( $args );
       foreach( $myposts as $post ) :
         $numero = $post->ID;
         update_post_meta( $numero, 'genere', 'Maschio' );
       endforeach; 
      }
  • This is a very old topic. The page I linked to above appears to be no longer available. There is some information on querying by repeater fields here https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

  • I tried this, but console gave me still “MarkerClusterer is not defined” and not work unfortunately. Did i something wrong? Thanks

    Here is my code

    (function($) {
    
    /*
    *  new_map
    *
    *  This function will render a Google Map onto the selected jQuery element
    *
    *  @type	function
    *  @date	8/11/2013
    *  @since	4.3.0
    *
    *  @param	$el (jQuery element)
    *  @return	n/a
    */
    
    function new_map( $el ) {
    	
    	// var
    	var $markers = $el.find('.marker');
    	
    	// vars
    	var args = {
    		zoom		: 16,
    		center		: new google.maps.LatLng(0, 0),
    		mapTypeId	: google.maps.MapTypeId.HYBRID
    	};
    	
    	
    	// create map	        	
    	var map = new google.maps.Map( $el[0], args);
    	
    	
    	// add a markers reference
    	map.markers = [];
    	
    	
    	// add markers
    	$markers.each(function(){
    		
        	add_marker( $(this), map );
    		
    	});
    	
    	// center map
    	center_map( map );
    	
    	
    	// add marker cluster
    	markerCluster( map.markers, map );
    	
    	
    	// return
    	return map;
    	
    }
    
    /*
    *  add_marker
    *
    *  This function will add a marker to the selected Google Map
    *
    *  @type	function
    *  @date	8/11/2013
    *  @since	4.3.0
    *
    *  @param	$marker (jQuery element)
    *  @param	map (Google Map object)
    *  @return	n/a
    */
    
    function add_marker( $marker, map ) {
    
    	// var
    	var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
    	
    	var defaultMarker = {
    		path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z M -2,-30 a 2,2 0 1,1 4,0 2,2 0 1,1 -4,0',
    	    fillColor: '#de6b6b',
    	    fillOpacity: 1
    	};
    	
    	var blueMarker = {
    		//path: 'M -1,0 A 1,1 0 0 0 1,0 1,1 0 0 0 -1,0 z',
    	    //path: google.maps.SymbolPath.CIRCLE,
    	    //fillColor: '#42bd2c',
    	    //fillOpacity: 1,
    	    //scale: 3,
    	    //strokeColor: "#42bd2c",
    	    //strokeWeight: 3,
    	    path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z M -2,-30 a 2,2 0 1,1 4,0 2,2 0 1,1 -4,0',
    	    fillColor: '#3292d6',
    	    fillOpacity: 1
    	}
    	
    	//Check your marker type, if it's green then set that otherwise leave it grey
    	var markerType = $marker.attr('data-marker')=="bluemarker"?blueMarker:defaultMarker;
    
    	// create marker
    	var marker = new google.maps.Marker({
    		position	: latlng,
    		icon		: markerType,
    		map			: map
    	});
    
    	// add to array
    	map.markers.push( marker );
    
    	// if marker contains HTML, add it to an infoWindow
    	if( $marker.html() )
    	{
    		// create info window
    		var infowindow = new google.maps.InfoWindow({
    			content		: $marker.html()
    		});
    
    		// show info window when marker is clicked
    		google.maps.event.addListener(marker, 'click', function() {
    
    			infowindow.open( map, marker );
    
    		});
    	}
    
    }
    
    /*
    *  center_map
    *
    *  This function will center the map, showing all markers attached to this map
    *
    *  @type	function
    *  @date	8/11/2013
    *  @since	4.3.0
    *
    *  @param	map (Google Map object)
    *  @return	n/a
    */
    
    function center_map( map ) {
    
    	// vars
    	var bounds = new google.maps.LatLngBounds();
    
    	// loop through all markers and create bounds
    	$.each( map.markers, function( i, marker ){
    
    		var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
    
    		bounds.extend( latlng );
    
    	});
    
    	// only 1 marker?
    	if( map.markers.length == 1 )
    	{
    		// set center of map
    	    map.setCenter( bounds.getCenter() );
    	    map.setZoom( 16 );
    	}
    	else
    	{
    		// fit to bounds
    		map.fitBounds( bounds );
    	}
    
    }
    
    function markerCluster( markers, map ) {
    	var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
    	console.log( markers );
    }
    
    /*
    *  document ready
    *
    *  This function will render each map when the document is ready (page has loaded)
    *
    *  @type	function
    *  @date	8/11/2013
    *  @since	5.0.0
    *
    *  @param	n/a
    *  @return	n/a
    */
    // global var
    var map = null;
    
    $(document).ready(function(){
    
    	$('.acf-map').each(function(){
    
    		// create map
    		map = new_map( $(this) );
    
    	});
    
    });
    
    })(jQuery);
  • If you could, just as a quick temporary fix, do you know if there’s a way to change the ‘Add New’ button to just create and save a blank draft? And then maybe to redirect to the edit page for that newly created blank draft? That way the custom fields would show up regardless.

Viewing 25 results - 10,951 through 10,975 (of 21,318 total)