I have done this way:
// Find connected pages (for all posts)
p2p_type( 'actors_movies' )->each_connected( $wp_query );
Now we have a $connected
property attached to every post on the $wp_query
, that is an array of posts connected by actors_movies
.
$actors = array();
while (have_posts()) : the_post();
$movies_acted = count($post->connected);
if($movies_acted > 0) {
$actors[$post->ID] = $movies_acted;
}
endwhile;
arsort($actors);
foreach ($actors as $id => $quantity) {
//Show the actor info
}
Then, I have made an array with the ID
of the $post
as the key
, and the quantity of $connected
as the value
, for each. Then I have ordered it by the value
, and I have done a foreach
through the array, to get the post from every ID
, starting from the most prolific =D
Related Posts:
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- Nested CPT URLs + Posts 2 Posts
- [Plugin: Posts 2 Posts] How does it work?
- Why is it important to deactivate a plugin before deleting it?
- Membership / subscription plugins – alternatives [closed]
- Using plural-only translation of register_post_status() in plugin
- admin-ajax returning 400 error when request is made with Fetch API
- Function to activate WordPress theme inside a plugin
- How do I retrieve a list of popular plugins using the WordPress.org Plugin API?
- Edit Imported advanced Custom Fields from wordpress Dashboard
- Restrict access and display for categories
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- Manually Removing Plugins
- Change My Basket text in the header of WooCommerce Artificer theme
- ACF for audio url in wordpress audio shortcode
- shortcode doesn’t work
- Built in admin ajax hooks?
- Will WordPress username displayed somewhere in the site?
- recommended breadcrumb plugins with possibility for hiding “Home” link [closed]
- dequeue not work
- Manually installed plugin doesn’t show up
- Could someone please help me to add category id with in this query so this will return posts from a certain category?
- Adding a section to admin menu for global settings
- upgrade plugin in wordpress
- Copyright messages for a particular set of pages
- building plugin and it is displaying above plugins page
- load_theme_textdomain path
- More than one text-domain is being used because of the included templates for plugins
- plugin development: problem with functions
- View Private Published Page with URL Code (no login required)
- How to update plugins with database updates if I use svn
- Why does my functions.php cause white-screen and media-library issues?
- Solutions to repost categories into multisite blogs?
- How can I force users to a particular subdomain to log in for MU (Multisite)?
- Why WordPress plugin url ajax doesn’t work?
- Added slug after URL permalink last slash returns different content
- How to escape the tailwindcss responsive syntax when using with contact form 7? [closed]
- Send reply with pre-prepared answers
- Using Wishlist Member and I need to access a user’s status
- $wpdb->get_row returns column name instead of column value
- How to add wp visual editor in a custom widget?
- How to get DEFER or ASYNC attribute to appear when I add a stylesheet with wp_enqueue_style from a plugin? [duplicate]
- allow photo/video in comments
- Excluding private/protected posts via IP
- Can’t get Gutenberg InspectorControls to work
- Some one is trying to hack my website, Need guidance [closed]
- WordPress premium theme development [duplicate]
- Mass SQL WordPress Meta Key deletion
- Gathering and logging data from a plugin: how to do it without race conditions?
- How to pass the API key to the client from the database? [closed]
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- How do I make a secure API call from a shortcode when a button is clicked?
- How to change the wp_upload_dir() path in plugin
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- How to add options to the plugin page?
- Odd /wp-admin/admin-ajax.php entries showing in Wassup
- wp-mail attachment is not sent for no reason?
- Plugin has added weird data in wp_options, set to autoload
- how to execute some code after a post is published in WordPress [duplicate]
- I can’t change permalink in WordPress 4.5.3
- Designing a plugin that uses an iFrame to process data in admin
- Could not add ‘LoginLogout’ link using BAW login logout plugin
- How to automatically activate users after registration without activation email?
- Pass PHP variable to javascript
- I want to add member to account in ultimate membership pro
- Make downloadable ebook read online without download option
- WordPress rewrite rule depend on meta values not ids
- JS working when used normally but not in wordpress
- Do i need to use a plugin for third party api integration?
- Problem with wordpress has_action() function
- WordPress – WPBakery – Near Footer jump issue
- Dequeue Table of Content font
- Display Woocommerce attribute name above product title
- In woocommerce, is there any way to empty wordpress default mini cart when order placed?
- Remove special characters from filenames
- My WordPress admin Lost All admin option, roles & privileges?
- Tracking sales/conversions in Woocommerce using Google Analytics
- How to make a website with two types of logins , Sellers and buyers?
- Rogue splash page keeps popping up
- Making a Custom Post Type Plugin – keep getting the white screen of death
- How to update plugins in a distributed wordpress scenario?
- Get plugin versions in xml/json format
- Shortcode registered from a plugin not recognized
- Make a wordpress site similar to Hot Or Not – Image rating system [closed]
- How to submit readme.txt file in wordpress directory
- wordpress shortcode A executing code from shortcode B
- Plugin for Reading Documents, PDF’s etc
- Simple Data Table Update and Page Integration
- How to create plugin list groups?
- Show latest and related articles from 3 different blogs
- Woocommerce custom fields
- This plugin throws error on the events page only [closed]
- WordPress Code Access to Restricted Content without Registration
- How to pre-set WordPress settings for specific posts?
- Two sites one PC
- PHP if url extension action=discussion condition use [closed]
- Is it possible to set different payment gateway on each Gravity Forms form? [closed]
- Social login authentication via wordpress rest api
- Multiple Post Thumbnails Not Returning URL for Background Image
- Is there any WordPress Plugin that provides video editing from front end side? [closed]