Stefancom
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Multiple WP instances, but one database of contentsAha, I see!
I got to say, the replication of the contents for a new site sounds like a very good idea. This should do the trick. Thank you very much, I will look into that.
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Count Media in Images FieldAbsolutely incredible! Works perfect. Thank you very much!
Best,
StefanDear Jory,
Thank you very much! That is a nice take on it. It would not differentiate the different taxonomies, though, right?
I have a feeling, that as long there won’t be many different taxonomies, the Yes/No check boxes may be a very simple and effective way to go.
Best,
Stefan
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] [if] tag not workingYes, of course! Thank you very much, Jim!
O.K., this too was not a good idea. I hope you can see what my code quote was intended to be about.
Postscriptum: The formatting of the code was not a good idea. Here I paste it again, including the formatting:
<?php
function total_pods($atts , $content = null ) {
extract(shortcode_atts(
array (
‘my_pod’ => ”
), $atts));$my_pods = pods( $my_pod , array( ‘limit’ => -1 ) );
return $my_pods->total_found();
}
add_shortcode( ‘count_pods’, ‘total_pods’ );
?><p>Number of Concerts: [count_pods my_pod =’concerts’]
<?php
//get Pods object for current post
$pod = pods( ‘concerts’, get_the_id() );
//get the value for the relationship field
$related = $pod->field( ‘composition’ );
//loop through related field, creating links to their own pages
//only if there is anything to loop through
if ( ! empty( $related ) ) {
count ( $related as $rel ) {
//get id for related post and put in ID
//for advanced content types use $id = $rel[ ‘id’ ];
$id = $rel[ ‘ID’ ];
//show the related post name as link
echo ‘‘.get_the_title( $id ).’‘;
//get the value for some_field in related post and echo it
$someField = get_post_meta( $id, ‘some_field’, true );
echo $someField;
} //end of foreach
} //endif ! empty ( $related )
?>Hey Jory @keraweb
Thank you very much for your comment!
So, I guess first of all the first part of my tries must go, yes? I base the solution fully on the Get Values from a Custom Relationship Field snippet?
<del datetime="2020-08-11T15:57:27+00:00"><?php function total_pods($atts , $content = null ) { extract(shortcode_atts( array ( 'my_pod' => '' ), $atts)); $my_pods = pods( $my_pod , array( 'limit' => -1 ) ); return $my_pods->total_found(); } add_shortcode( 'count_pods', 'total_pods' ); ?> <p>Number of Concerts: [count_pods my_pod ='concerts']</del> <?php //get Pods object for current post $pod = pods( 'concerts', get_the_id() ); //get the value for the relationship field $related = $pod->field( 'composition' ); //loop through related field, creating links to their own pages //only if there is anything to loop through if ( ! empty( $related ) ) { count ( $related as $rel ) { //get id for related post and put in ID //for advanced content types use $id = $rel[ 'id' ]; $id = $rel[ 'ID' ]; //show the related post name as link echo '<a href="'.esc_url( get_permalink( $id ) ).'">'.get_the_title( $id ).'</a>'; //get the value for some_field in related post and echo it $someField = get_post_meta( $id, 'some_field', true ); echo $someField; } //end of foreach } //endif ! empty ( $related ) ?>
That would me leave with the code above, yes? I changed the the pod name and the relationship field name to my case.
But then, WordPress confronts me with an error (Parse error: syntax error, unexpected ‘as’ (T_AS), expecting ‘)’ in code on line 9). Has that to do with $related as $rel, now that I changed foreach to count? That probably is not right?
Furthermore, this code is to echo a list, right? But, how could I make it echo a mere number instead? With something like echo count($related);?
Would the $id = $rel[ ‘ID’ ]; bit even be necessary for what I intend, like, maybe I should shorten the code even more?
Best,
Stefan
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Sequential number, order numberHi Alphonse,
Thank you very much for your efforts to explain it to me, I appreciate it! Unfortunately, I still fail to get this function to work. Maybe you could have one more look at it?
So, I have two pods: “work” and “performances”. They are connected: In “performances”, there is a relationship field called “composition”, which refers to the pod “work”. Like this, “performances” are always related to one “work”, that is performed.
Now, in the “work” template, I want to include a counter, that displays the total number of performances of this very work.
(1) First thing I did was this adaption of your code:
<?php function total_pods($atts , $content = null ) { extract(shortcode_atts( array ( 'my_pod' => '' ), $atts)); $my_pods = pods( $my_pod , array( 'limit' => -1 ) ); return $my_pods->total_found(); } add_shortcode( 'count_pods', 'total_pods' ); ?> <p>Number of performances: [count_pods my_pod ='performances']
And it kind of worked! It does display the total number of performances – but of all, that were ever entered. Yet, what I want, is only that selection of performances, where the field “composition” relates to the “work” page that the user am on at that moment.
(2) Then you proposed to me this:
<?php // Ajout Shortcode : nombre de taxonomies function total_categories($atts ) { //Parametres extract(shortcode_atts( array ( 'my_categorie' => '' ), $atts)); //Compte les taxonomies $args = array( 'taxonomy' => $my_categorie, 'hide_empty' => true ); // Return return wp_count_terms ($my_categorie, $args ); } add_shortcode( 'nombre_categories', 'total_categories' ); ?> [nombre_categories my_categorie = 'performances'] // counte the the catégorie of the pods [les_categories my_categorie = "performances" ] //lit the categorie
But it get an error, and maybe I did not adapt your code correctly. (It says: “Catchable fatal error: Object of class WP_Error could not be converted to string on line 343”).
(3) And the list code, that you posted last, looks really cool! I do not really need it at this point, but I tried to make it work anyways, yet failed as well.
Would you have a piece of advice for me, why the codes would not work in my template? Did I adapt the code incorrectly? It appears you did find the solution for this issue already, but I do not succeed to get it to work in my specific situation.
Thanks!!
Stefan
Hi s1s2
Had you figured out a solution to you or first question? I a looking for that too and would be interested to hear how you solve it.
Thanks
StefanForum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Sequential number, order numberHi Alphonse,
I am looking for a counting solutions as well, and I think what you came up with is half-way there.
I adapted your code:
<?php function total_pods($atts , $content = null ) { extract(shortcode_atts( array ( 'my_pod' => '' ), $atts)); $my_pods = pods( $my_pod , array( 'limit' => -1 ) ); return $my_pods->total_found(); } add_shortcode( 'count_pods', 'total_pods' ); ?> <p>Number of performances: [count_pods my_pod ='performances']
Thank you for that!
And it does work: It displays the total number of entries in that pod called “performances”.
But I want that number to be selective, to only count those “performances” with one of that pod’s fields having a specific value.
I am not really sure: Were you trying to do the same thing, a selective count? And did you figure out a solution for that? I fail to find one.
Stefan
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Count pod entries with “where=”?In the meantime, I tried this out:
<?php $term = get_term( 1, '{@composition.id}' );//for example uncategorized category echo 'count: '. $term->count; ?>
“get_term” – that probably goes in the right direction? But I have no success yet.
… See, there is a display of events that feature the one specific composition (“work”), whose page the user is just reading:
[pods name="performances" orderby="concert_date DESC" limit="-1" where="composition.id = {@id}" template="Performance List at Work Page"]
And this list of related events works perfectly well. All I want is to also display the number of events which appear, the sum of the displayed entries. That should be easily possible? Because, like, Pods is displaying 4 events, so I should be able to let Pods also display the number “4”?
Thanks!
Hi!
Well … this, too, I was able to solve on my own. Sorry for asking so quickly before going deeper into the issue myself.
So, I just switched the block editor to HTML version, and copy-pasted that into my template. Works nicely!
Stefan
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Conditional fieldsHi,
So, I need to apologize for the many confusing messages. Turns out, spending those hours was absolutely worth it–and Jim True’s before mentioned advice from 2017 did the trick!
This is what he had commented to another user:
If this is a single-select, you can’t use the EACH wrapper, but you also can’t use traversal, so if you’re trying to reach DOWN into a linked record that’s linked to the one you’re currently traversing (ie data that’s linked to the linked faculty profile), you need to do that with a separate template that goes through a faculty profile and outputs what you want and is called from the current post with:
[pods name="faculty-profiles" where="employee.ID = {@ID}" template="Faculty Profile"]
And what can I say? I jut got it to work!!!
Thanks, Jim! I am sorry for this thread, when eventually I was able to figure it out on my own. Thanks for the great only resources (including the Podscast).
This thread can be marked as resolved.
Stefan
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Conditional fieldsYeah, I think I will not be able to fix this. Interestingly, I found the following notes by Jim True:
https://pods.io/forums/topic/how-to-conditionally-display-related-post-data-in-pods-template/
It is about using the IF tag, and that may be something for me to look into. In that example (not mine) he suggests to work with a separat template (including “where =”), and I have the feeling this could be something that may lead me to a solution. Would someone have a hint which helps me go the right path?
Forum: Plugins
In reply to: [Pods - Custom Content Types and Fields] Conditional fieldsI was trying to use Find, like this:
<?php $performances = pods( 'performances' ); $params = array( 'orderby' => 'performances.concert_date DESC', 'limit' => -1, 'where' => "'performance.composition' = 'works.post_title'" ); $performances->find( $params ); while ( $performances->fetch() ) { echo $performances->display( 'performances' ); } ?>
But can PHP be used in the template at all? It appears not to work.