• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

AgentPress Listing Loop Filter Modification

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › AgentPress Listing Loop Filter Modification

This topic is: resolved

Tagged: agentpress plugin, custom filter

  • This topic has 6 replies, 3 voices, and was last updated 9 years, 2 months ago by carasmo.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • January 28, 2017 at 9:12 am #200173
    dmor71
    Participant

    In need help to filter the AgentPress Loop to change the text from "View Listing" to "Book Now" on the archive listing page/homepage. You can see the site here https://webclient.co/running

    I can see where to change the text in the plugin but I can't figure out how to write a filter for my child theme functions.php file so that it won't revert back after a plugin update. Thanks. Below is the loop code from the plugin.

    <?php
    class AgentPress_Featured_Listings_Widget extends WP_Widget {
    
    	function __construct() {
    		$widget_ops = array( 'classname' => 'featured-listings', 'description' => __( 'Display grid-style featured listings', 'agentpress-listings' ) );
    		$control_ops = array( 'width' => 300, 'height' => 350 );
    		parent::__construct( 'featured-listings', __( 'AgentPress - Featured Listings', 'agentpress-listings' ), $widget_ops, $control_ops );
    	}
    
    	function widget( $args, $instance ) {
    	
    		/** defaults */
    		$instance = wp_parse_args( $instance, array(
    			'title'          => '',
    			'posts_per_page' => 10
    		) );
    	
    		extract( $args );
    		
    		echo $before_widget;
    		
    			if ( ! empty( $instance['title'] ) ) {
    				echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
    			}
    			
    			$toggle = ''; /** for left/right class */
    			
    			$query_args = array(
    				'post_type'      => 'listing',
    				'posts_per_page' => $instance['posts_per_page'],
    				'paged'          => get_query_var('paged') ? get_query_var('paged') : 1
    			);
    			
    			query_posts( $query_args );
    			if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    				//* initialze the $loop variable
    				$loop        = '';
    
    				//* Pull all the listing information
    				$custom_text = genesis_get_custom_field( '_listing_text' );
    				$price       = genesis_get_custom_field( '_listing_price' );
    				$address     = genesis_get_custom_field( '_listing_address' );
    				$city        = genesis_get_custom_field( '_listing_city' );
    				$state       = genesis_get_custom_field( '_listing_state' );
    				$zip         = genesis_get_custom_field( '_listing_zip' );
    
    				$loop .= sprintf( '<a href="%s">%s</a>', get_permalink(), genesis_get_image( array( 'size' => 'properties' ) ) );
    
    				if ( $price ) {
    					$loop .= sprintf( '<span class="listing-price">%s</span>', $price );
    				}
    
    				if ( strlen( $custom_text ) ) {
    					$loop .= sprintf( '<span class="listing-text">%s</span>', esc_html( $custom_text ) );
    				}
    
    				if ( $address ) {
    					$loop .= sprintf( '<span class="listing-address">%s</span>', $address );
    				}
    				
    				if ( $city || $state || $zip ) {
    
    					//* count number of completed fields
    					$pass = count( array_filter( array( $city, $state, $zip ) ) );
    
    					//* If only 1 field filled out, no comma
    					if ( 1 == $pass ) {
    						$city_state_zip = $city . $state . $zip;
    					}
    					//* If city filled out, comma after city
    					elseif ( $city ) {
    						$city_state_zip = $city . ", " . $state . " " . $zip;
    					}
    					//* Otherwise, comma after state
    					else {
    						$city_state_zip = $city . " " . $state . ", " . $zip;
    					}
    
    					$loop .= sprintf( '<span class="listing-city-state-zip">%s</span>', trim( $city_state_zip ) );
    
    				}
    
    				$loop .= sprintf( '<a href="%s" class="more-link">%s</a>', get_permalink(), __( 'View Listings', 'agentpress-listings' ) );
    
    				$toggle = $toggle == 'left' ? 'right' : 'left';
    
    				/** wrap in post class div, and output **/
    				printf( '<div class="%s"><div class="widget-wrap"><div class="listing-wrap">%s</div></div></div>', join( ' ', get_post_class( $toggle ) ), apply_filters( 'agentpress_featured_listings_widget_loop', $loop ) );
    
    			endwhile; endif;
    			wp_reset_query();
    		
    		echo $after_widget;
    		
    	}
    
    	function update( $new_instance, $old_instance ) {
    		return $new_instance;
    	}
    
    	function form( $instance ) {
    		
    		$instance = wp_parse_args( $instance, array(
    			'title'          => '',
    			'posts_per_page' => 10
    		) );
    			
    		printf( '<p><label for="%s">%s</label><input type="text" id="%s" name="%s" value="%s" style="%s" /></p>', $this->get_field_id('title'), __( 'Title:', 'agentpress-listings' ), $this->get_field_id('title'), $this->get_field_name('title'), esc_attr( $instance['title'] ), 'width: 95%;' );
    		
    		printf( '<p>%s <input type="text" name="%s" value="%s" size="3" /></p>', __( 'How many results should be returned?', 'agentpress-listings' ), $this->get_field_name('posts_per_page'), esc_attr( $instance['posts_per_page'] ) );
    		
    	}
    }
    https://webclient.co/running
    January 28, 2017 at 11:00 am #200184
    Victor Font
    Moderator

    You are looking in the wrong place. The View Listing is the text for the WordPress more link. Open archive-listing.php and change line 86:

    $loop .= sprintf( '<a href="%s" class="more-link">%s</a>', get_permalink(), __( 'View Listing', 'agentpress' ) );


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 28, 2017 at 3:59 pm #200196
    dmor71
    Participant

    Thanks for reaching out Victor. But I have figured out where to change the text in the plugin but that won't help as it will revert back when the plugin is updated. I need help writing a filter that I can put in my child theme's functions.php so that any plugin updates won't effect the change. Do you know how to do that?

    January 28, 2017 at 4:23 pm #200197
    Victor Font
    Moderator

    Copy the plugin into the child theme's widget directory and modify it as your own.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 30, 2017 at 11:56 am #200265
    carasmo
    Participant

    I answered this on StackOveflow:

    http://stackoverflow.com/questions/41911137/how-to-filter-loop-in-genesis-studiopress-agentpress-listings-plugin/41941243#41941243

    The answer is on this forum already:

    Agent Press Listing

    You would add this to your functions.php file and change the words as needed. When your plugin updates, the words won't change:

    
    /**
     * Filter the loop output of the AgentPress Featured Listings Widget.
     */
    function agentpress_featured_listings_widget_loop_filter( $loop ) {
    
        $loop = ''; /** initialze the $loop variable */
    
        $loop .= sprintf( '<a href="%s">%s</a>', get_permalink(), genesis_get_image( array( 'size' => 'properties' ) ) );
    
        $loop .= sprintf( '<span class="entry-title">' . ( get_the_title() ) . '</span>' );
    
        $loop .= sprintf( '<span class="listing-price">%s</span>', genesis_get_custom_field('_listing_price') );
    
        $custom_text = genesis_get_custom_field( '_listing_text' );
        if( strlen( $custom_text ) )
            $loop .= sprintf( '<span class="listing-text">%s</span>', esc_html( $custom_text ) );
    
        $loop .= sprintf( '<span class="listing-address">%s</span>', genesis_get_custom_field('_listing_address') );
    
        $loop .= sprintf( '<span class="listing-city-state-zip">%s %s, %s</span>', genesis_get_custom_field('_listing_city'), genesis_get_custom_field('_listing_state'), genesis_get_custom_field('_listing_zip') );
    
        // Here is where you change the text:
        $loop .= sprintf( '<a href="%s" class="more-link">%s</a>', get_permalink(), __( 'Book Now', 'yourtextdomain' ) );
    
        return $loop;
    
    }
    add_filter( 'agentpress_featured_listings_widget_loop', 'agentpress_featured_listings_widget_loop_filter', 10, 1 );

    Genesis Theme Customization and Help

    January 31, 2017 at 11:48 am #200330
    dmor71
    Participant

    carasmo,
    Thank you very much. That did the trick.

    January 31, 2017 at 12:06 pm #200332
    carasmo
    Participant

    Great. Please choose it as the answer at SO:

    http://stackoverflow.com/questions/41911137/how-to-filter-loop-in-genesis-studiopress-agentpress-listings-plugin/41941243#41941243


    Genesis Theme Customization and Help

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble