Support

Home Forums Event Espresso Premium People plugin sort order for archive page 2

People plugin sort order for archive page 2

Posted: August 27, 2018 at 9:22 am


WEMconference

August 27, 2018 at 9:22 am

Hi

I had to move on to other issues but i have still not managed to resolve this…

https://eventespresso.com/topic/people-plugin-sort-order-for-archive-page/

Is there a way for me to order the speakers by changing the database ID’s of the people as a quick fix?

To answer this…

https://eventespresso.com/topic/people-plugin-sort-order-for-archive-page/#post-273033

I have created installed and activated the plugin as you advised but still have no “People” menu item? can you advise as to why this might be?

Thanks!


Josh

  • Support Staff

August 27, 2018 at 10:29 am

Is there a way for me to order the speakers by changing the database ID’s of the people as a quick fix?

You’ll break all relationships to events and taxonomies if you do that.

I have created installed and activated the plugin as you advised but still have no “People” menu item? can you advise as to why this might be?

I think that hook has been deprecated since the time of that other topic. Along with that, we can try a different approach that avoids additional plugins to re-order the items in the people post archive on the front end. You can add the following code to your functions file:

https://gist.github.com/joshfeck/326c0a511afa8b829405157762f9f7a9

The first function adds a Post Attributes meta box, with one field (Order). You’ll input 1 for the first item to be displayed, 2 for the second and so on. The second function takes those values and applies them to the native WP custom post type archive so they’ll display in the set order.


WEMconference

August 28, 2018 at 3:53 am

Hi Josh

Thanks for the update this seem like a great solution but i have implemented it on my local machine and it has thrown these errors….

Fatal error: Uncaught Error: Call to undefined function write_log() in C:\xampp\htdocs\websites\expo\wp-content\themes\Zephyr-child\functions.php:126 Stack trace: #0 C:\xampp\htdocs\websites\expo\wp-includes\class-wp-hook.php(286): ee_modify_page_attributes_of_event_espresso_cpt(Array) #1 C:\xampp\htdocs\websites\expo\wp-includes\plugin.php(203): WP_Hook->apply_filters(Array, Array) #2 C:\xampp\htdocs\websites\expo\wp-content\plugins\event-espresso-core-reg\core\domain\entities\custom_post_types\CustomPostTypeDefinitions.php(180): apply_filters('FHEE__EventEspr...', Array) #3 C:\xampp\htdocs\websites\expo\wp-content\plugins\event-espresso-core-reg\core\domain\services\custom_post_types\RegisterCustomPostTypes.php(58): EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions->getDefinitions() #4 C:\xampp\htdocs\websites\expo\wp-content\plugins\event-espresso-core-reg\core\EE_System.core.php(1099): EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes->registerCustomPostTypes() # in C:\xampp\htdocs\websites\expo\wp-content\themes\Zephyr-child\functions.php on line 126

Any idea whats going on please?

Thanks again,
Ben.


WEMconference

August 28, 2018 at 3:56 am

I do have this in my funtions file will it be effecting the new code above?

//* Change the default people slug to something else in Event Espresso 4
add_filter( 'FHEE__EE_Register_CPTs__register_CPT__rewrite', 'ee_custom_people_slug', 10, 2 );
function ee_custom_people_slug( $slug, $post_type ) {
    if ( $post_type == 'espresso_people' ) {
        $custom_slug = array( 'slug' => 'speakers' );
        return $custom_slug;
    }
    return $slug;
}

Thanks again
Ben.


Josh

  • Support Staff

August 28, 2018 at 7:10 am

I’m sorry about that. There was a line of debug code remaining in the gist. That has now been removed. The corrected code resides at:

https://gist.github.com/joshfeck/326c0a511afa8b829405157762f9f7a9


WEMconference

August 28, 2018 at 9:04 am

Hi Josh

Thanks that has now added the post attributes meta box so i can enter the order. I have added numbers 1-5 to some of the people but they are not ordering on the page. Could this be because i have created a short code to show them on the page?

This is the shortcode [display_speakers] and its corresponding code i have in my functions…

function display_speakers(){
 $template_vars = array(
    'layout' => "classic",
    'type' => "grid",
    'columns' => 6,
    'img_size' => "us_400_400_crop",
    'metas' => (array) us_get_option( 'archive_meta', array() ),
    'content_type' => "grid",
    'show_read_more' => 0,
    'pagination' => us_get_option( 'archive_pagination', 'regular' ),
);
 $the_content = us_load_template( 'templates/blog/listing', $template_vars );
 echo $the_content;
}
add_shortcode("display_speakers","display_speakers");


Josh

  • Support Staff

August 28, 2018 at 10:39 am

Yes, it’s quite likely because you’re using a custom shortcode to display those. We actually do not support custom shortcodes or custom theme templates. You can check with the author of the shortcode/theme to find out how to change the order of that shortcode’s output.


WEMconference

August 29, 2018 at 4:18 am

Hi Josh

Is there no easy way to make it work with this code? I found it on a forum so have no further access to the developer?


Josh

  • Support Staff

August 29, 2018 at 6:15 am

The code you posted here lacks enough context to give you an answer. For example, does the us_load_template() function accept an “order_by” type parameter, and does it access the post’s meta? If you can get the source of that function, and any other custom functions it may call we can investigate further.


WEMconference

August 29, 2018 at 6:30 am

Hi Josh

I will look into this further and see if i can find this out thanks.

If us_load_template() does accept the “order_by” function how would i add that?

Thanks again
Ben.


Josh

  • Support Staff

August 29, 2018 at 6:51 am

Hi Ben,

The answer will depend on how that us_load_template() function is coded.


WEMconference

August 29, 2018 at 7:16 am

Hi Josh

I think this is where us_load_template() is defined in the Zephyr Themes helpers.php does this help?

/**
 * Load some specified template and pass variables to it's scope.
 *
 * (!) If you create a template that is loaded via this method, please describe the variables that it should receive.
 *
 * @param string $template_name Template name to include (ex: 'templates/form/form')
 * @param array  $vars          Array of variables to pass to a included templated
 */
function us_load_template( $template_name, $vars = NULL ) {

	// Searching for the needed file in a child theme, in the parent theme and, finally, in the framework
	$file_path = us_locate_file( $template_name . '.php' );

	// Template not found
	if ( $file_path === FALSE ) {
		do_action( 'us_template_not_found:' . $template_name, $vars );

		return;
	}

	$vars = apply_filters( 'us_template_vars:' . $template_name, (array) $vars );
	if ( is_array( $vars ) AND count( $vars ) > 0 ) {
		extract( $vars, EXTR_SKIP );
	}

	do_action( 'us_before_template:' . $template_name, $vars );

	include $file_path;

	do_action( 'us_after_template:' . $template_name, $vars );
}

/**
 * Get some specified template output with variables passed to it's scope.
 *
 * (!) If you create a template that is loaded via this method, please describe the variables that it should receive.
 *
 * @param string $template_name Template name to include (ex: 'templates/form/form')
 * @param array  $vars          Array of variables to pass to a included templated
 *
 * @return string
 */
function us_get_template( $template_name, $vars = NULL ) {
	ob_start();
	us_load_template( $template_name, $vars );

	return ob_get_clean();
}


Josh

  • Support Staff

August 29, 2018 at 7:56 am

No I’m afraid that does not help. Does that theme have any developer documentation? If not, you could go with a standard WP_Query instead of using the template functions.


WEMconference

August 29, 2018 at 10:27 am

Hi Josh

No developer documentation i’m afraid, could you point me in the right direction of how to implement a WP_query i have read this but am still unsure how to implement it to order the people.

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Thanks again i really appreciate your help,
Ben.


WEMconference

August 29, 2018 at 10:29 am

Hi Josh

Could you elaborate as to how the WP_query can be used in this case to sort the people? I have read through this but am still not sure as to exacly how this could be achieved

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Thanks again i really apprieciate your help,
Ben.


Josh

  • Support Staff

August 29, 2018 at 2:39 pm

Hi Ben,

The Event Espresso plugin & the people add-on use the WP_Query by default when it does the People custom post type archive. You do not need to mess with that part, you just remove the shortcode and change things back to use the people add-on archive like when the plugin was first activated.

Then, if you want to alter the template for the archive, you make a copy of your theme’s archive.php file, rename it to be archive-espresso_people.php, then make alterations to that file.

If for some reason your theme does not use an archive.php template for displaying post type archives, this plugin will help you find which template it does use:

https://wordpress.org/plugins/show-current-template/


WEMconference

August 29, 2018 at 2:56 pm

Hi Josh

I will give that a go thanks, there was a reason for using the shortcode to get around problems with the theme and customising the page. I have a custom revolution slider at the top of that page and could not get it working correctly with the default archive page it was using.

Thanks again!
Ben.

The support post ‘People plugin sort order for archive page 2’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso