Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter naminta

    (@naminta)

    Thanks for pointing that out with the source code. Your were right, there is a location where the loop can be found and edit. Thank you very much (again ?? )

    Thread Starter naminta

    (@naminta)

    @bcworkz, you were right, array did not worked that way, made an rework today, just if someone wants to use this, here is the reworked Maincode:

    <?php
    $userid = wp_get_current_user();
    
    //Array for the s argument
    $userfields = array(get_cimyFieldValue($userid, 'field1'), get_cimyFieldValue($userid, 'field2'), get_cimyFieldValue($userid, 'fieldn'));
    
    //Testprint for the array
    //var_dump($userfields);
    
    //for-loop to run the array
    for ($i=0; $i<count($userfields); $i++){
    
    //Query + headline for the argument on position i
    echo '<h4>Posts for the user field ' . $userfields[$i] . '</h4>';
    $query = new WP_Query( array( 's' => $userfields[$i] ) );
    
    if ( $query->have_posts() ) {
    	echo '<ul>';
    	while ( $query->have_posts() ) {
    		$query->the_post();
    		//Only if no Page
    		if (get_post_type() == 'page'){
    			//do nothing
    		}
    		else{
    			echo '<li>';
    			echo "<a href='" . get_permalink() . "'>" . get_the_title() . " | Post date: " . get_the_date( 'd-m-Y' ) . "</a>";
    			echo '</li>';
    		}
    	}
    	echo '</ul>';
    	/* Restore original Post Data */
    	wp_reset_postdata();
    }
    else {
    	echo '<p>No Posts for the Topic ' . $userfields[$i] . '.</p>';
    }
    }
    ?>

    Now it is solved, to get the array dynamic filled you could work with a switch case or if else and check for empty variables, could look like this:

    <?php
    $userid = wp_get_current_user();
    
    $field1 = '';
    $field2 = '';
    $field3 = '';
    
    $userfield = array();
    
    if ($field1 != '' && $field2 != '' §§ field3 != ''){
    $userfields = array(get_cimyFieldValue($userid, 'field1'), get_cimyFieldValue($userid, 'field2'), get_cimyFieldValue($userid, 'field3'));
    }
    ifelse (...........and so on ....
    
    • This reply was modified 8 years ago by naminta.
    Thread Starter naminta

    (@naminta)

    hey solved it myself, for everyone who is intressted here is the mainpart of my code

    @bcworkz ‘sS agrgument worked with an array for me ??
    don’t why, but it does, $userfields is still an array, now it is just simple html to get the users the content shown as i want it to look =>

    thank you very much for your help

    CODE:

    $userid = wp_get_current_user();
    
    //Array for the s argument
    $userfields = array(get_cimyFieldValue($userid, 'field1'), get_cimyFieldValue($userid, 'field2'), get_cimyFieldValue($userid, 'fieldn'));
    
    //Testprint if you have new arguments to look for
    //var_dump($userfields);
    
    //Query
    $query = new WP_Query( array( 's' => $userfields ) );
    
    //Loop
    if ( $query->have_posts() ) {
    	echo '<ul style="text-align: center;">';
    	while ( $query->have_posts() ) {
    		$query->the_post();
    		//No Pages!
    		if (get_post_type() == 'page'){
    			//do nothing
    		}
    		else{
    			echo '<li>';
    			echo "<a href='" . get_permalink() . "'>" . get_the_title() . " | Post date: " . get_the_date( 'd-m-Y' ) . "</a>";
    			echo '</li>';
    		}
    	}
    	echo '</ul>';
    	/* Restore original Post Data */
    	wp_reset_postdata();
    }
    else {
    	echo '<p>No Posts for the Topic ' . $array[i] . '</p>';
    }
    Thread Starter naminta

    (@naminta)

    not the super php dude

    <?php
    
    function get_special_user_content (){
    	
    	$userid = wp_get_current_user();	
    	$userfields = array(get_cimyFieldValue($userid, 'PFLEGEGRAD'), get_cimyFieldValue($userid, 'BEHINDERUNGSGRAD'), get_cimyFieldValue($userid, 'ORT'), get_cimyFieldValue($userid, 'PLZ'));
    	
    	//The Loop to run arraypositons
    	for ($i = 0; $i < count($userfields); $i++){
    		
    		//The Querry argument (for every userfield new)
    		$query = new WP_Query( array( 's' => $userfields[i] ) );
    	
    		// The Loop to display content
    		if ( $query->have_posts() ) {
    			echo '<ul>';
    			while ( $query->have_posts() ) {
    				$query->the_post();
    				echo '<li>' . get_the_title() . '</li>';
    			}
    			echo '</ul>';
    			/* Restore original Post Data */
    			wp_reset_postdata();
    		}
    		else {
    			echo '<p>Keine Beitr?ge für Ihre Benutzerangabe ' . $array[i] . 'gefunden</p>';
    		}
    	}
    }
    
    ?>

    What you think, could that work?
    And i am still new in using wordpress, maybe someone have an advise how i can get my snippet on an page and into the CMS itself.

    I would suggest using the PlugIn My Custom Functions to add the code to the functions.php. With the PlugIn Insert PHP I would display the function on a page.

    Any easier ways?

    EDIT: Tested the array with var_dump();, works, other code is not working like i would wish it should

    • This reply was modified 8 years, 1 month ago by naminta. Reason: Test on my array
    Thread Starter naminta

    (@naminta)

    Hey @bcworkz,

    while coding there was one more thing i would like to ask, is it possible to use an array here for keyword:

    $query = new WP_Query( array( 's' => 'keyword' ) );

    otherwise i would build a loot around and try it this way.

    Thread Starter naminta

    (@naminta)

    Sounds like what i was searching for, will try this and give you a feedback ??

    Maybe if i code like an idiot i will write before finishing ^^
    but first i will try it by myself ??

    thx so far

    Hey,

    first: love to use your plugin.

    Is the function still in the wishlist, because I would need it too ??

    Thanks ??

Viewing 7 replies - 1 through 7 (of 7 total)