The foreach tag has no wiki summary.
-1
votes
1answer
15 views
Eliminate duplicates in a foreach loop [closed]
I've created a filter for my search results that allows people to filter user searches based on their State from their profile. The problem I am having is that there are duplicate states showing in ...
0
votes
0answers
18 views
Custom widget using get_categories select menu dropdown
I have created a custom widget that is supposed to display a select menu with all the categories the blog has. I have used get_categories to compile the list. This works fine and all categories appear ...
0
votes
0answers
47 views
How to exclude child terms from tax query foreach loop
I have this query which is working fine but I can not get it to exclude child terms and include only parent terms. This is what I have so far --
<?php
$custom_terms = get_terms('videoscategory');
...
0
votes
0answers
23 views
Create Pagination in Term list
I need to create numeric pagination in term list.
Is there some options I can do this, i need to create a numeric pagination like the one we have for posts using wp-page-navi.
Here is the code I am ...
0
votes
0answers
23 views
Group Date Archives by term_id
I am trying to group posts in Yearly date archive page by term:
here is the code I am using :
<?php
$terms = get_terms("publicationcat");
$count = count($terms);
if ( ...
0
votes
0answers
83 views
Foreach displaying all posts and not the value set in WP back end
Pagination just isn't working correctly with my foreach code. I have to manually set the post per page count for it to work but I'd like it to use the WP back end value (Set in settings > reading) ...
0
votes
1answer
52 views
Paginating a list of all posts collected by category titles
I'd be really grateful if anyone has any ideas about what might be wrong with this code or, alternatively, could suggest an entirely different way of achieving the same aims.
I have a site (staged, ...
0
votes
1answer
122 views
Pagination for multiple queries merging into one Loop
I have an events site where I want to display upcoming events that can be booked in ascending date order and then events that are closed for registration in descending order.
I'm using get_posts for ...
0
votes
1answer
131 views
update_post_meta only updating on last loop of foreach
I'm building a way to upload multiple files for an announcement custom post type on the front end. My function here uploads any number of files succesfully so I can see them under "Media" in ...
1
vote
0answers
17 views
How to write an efficient metabox with repetitive fields [duplicate]
Possible Duplicate:
Create more Meta Boxes as needed
I’m having a hard time to write an efficient code for the below Metabox. Since I do not want to use any third-party class, I’m trying to ...
0
votes
1answer
249 views
How to get the next and previous image title from attachment or gallery?
I'm trying to build a slider exactly like http://goo.gl/A7WtZ in wordpress. I have managed to make the slider work except the next/prev button. I need to get the next image title and the previous ...
0
votes
1answer
74 views
Insert new post for each user infinite loop error
I wrote this little function to automatically create a post for every user of the blog but it creates an infinite loop (I disabled it to stop it creating new posts). I'm not very skilled in php, I ...
0
votes
1answer
75 views
How to reduce three query to one in multiple output template?
I would like to publish 7 posts from the same category but embedded in different DIV or UL.
How could I simplify this code?
<?php
$query01 = array( 'numberposts' => 1, 'offset'=> 0, ...
0
votes
0answers
54 views
Adding sticky class to most viewed posts [closed]
I'm trying to write a function in functions.php that promotes a post to featured depending on how many times has been viewed. For the views I'm using a plugin method. Still I'm not able to loop ...
2
votes
2answers
275 views
Display data from a non wordpress database on a page template
I am using a sql query to access information to display on a wordpress page by adding the below code to a page template. I know the query works as I've tested it in phpmyadmin.
$rows = ...
0
votes
1answer
175 views
foreach repeat html structure after every nth for attachment [closed]
I am trying to achieve result with below structure in foreach loop where after every two images it will repeat entire structure.
I have some basic knowledge for something I can use eg. counter++; and ...
0
votes
2answers
221 views
Meta Box Plugin Cloned Fields - Multiple Foreach values
I have the following code that I can't get working. I have two cloneable fields that are being output as one entity (URL and thumbnail image). These are cloned fields using the Meta Box Plugin by ...
2
votes
2answers
535 views
Count total number of post in foreach loop
I used the the following script (only with get_permalink....) to display posts from a post type where the post author has an extra meta field on his user page:
<?php // get users from user page
...
0
votes
2answers
58 views
Way of getting queried loop before the query with a filter hook?
Is there a way to get the results of a loop with a filter before the code for the loop is performed in the structure of your code?
My markup is something like this:
<body>
<div>
/* ...
0
votes
1answer
169 views
Compare current post Category in select menu
i have done this many times but not via a form so i am getting a weird issues when trying to assign a "selected" based on the current post term id...
Maybe the use of get_the_category and then ...
0
votes
1answer
231 views
Why use foreach to get attachment_id if numberposts is equal to 1?
I needed to pass an image to a Pinterest plugin in posts without a Featured Image so I wrote a little function to get the id of the first picture in a post. This code is in the loop-single.php where ...
1
vote
1answer
155 views
Get posts inside Get terms problem
i have a get_terms which loads correctly.
inside of it i have used get_posts. then using get posts i am
trying to get each post tags (and count <= not currently inside this script)
<?php
...
0
votes
1answer
290 views
Passing a variable from a FOREACH loop in a link
How would you pass a variable from a foreach loop, through a link? I have tabs that display correctly. The jQuery works. But when I call the variable $category down where the content sorts, $category ...
0
votes
1answer
221 views
Sets post_parent in custom post type posts automatically based on cpt->page name
I'm trying to write a function that will "pair" my custom post type with a page with the same name as the custom post type.
The aim is that when a custom post type is saved, it checks if there's a ...
0
votes
2answers
69 views
How to randomise my menu items?
So I thought I could do it like this (also I want to only get 3) -
$menu_items = wp_get_nav_menu_items(26);
$menu_items = array_rand($menu_items, 3);
foreach ( (array) $menu_items as $key => ...
0
votes
2answers
150 views
How to check all items in a loop have post thumbnail?
Currently I have the following loop:
<?php
$shows_sales = get_posts(array(
'post_type' => 'show_sale',
'post_status' => 'publish',
'posts_per_page' => 3,
));
$done_image = ...
0
votes
1answer
169 views
Loop not displaying comments_popup_link
I cannot get the comments_popup_link to display with the posts retrieved by the foreach loop. Only the title and permalink are displayed. Any idea why the comment link is left out?
<?php
...
2
votes
2answers
977 views
How to get permalink and title from post ID?
I have stored an array of post IDs and I would like to list the posts as links, meaning I need to get the title and permalink for the post ID - $id. The list should be echoed out by the following if ...
0
votes
1answer
171 views
Can't seem to get set_blog_id working, it just doesn't reset the blog ID
Trying to iterate through a list of the sites and I can't seem to get set_blog_id working. Here's the sample output:
Array ( [0] => stdClass Object ( [blog_id] => 2 ) [1] => stdClass Object ( ...
-1
votes
2answers
186 views
Different Output for “Every Other” Foreach Statement?
I'm currently using the following code in order to get subcategories in a category page and getting the posts foreach subcategory. In the part where it echos "span-12" (line 14) i want it to echo ...
0
votes
2answers
150 views
Lists Top Authors by Most Recent Posts
I'm trying to display a table format of the top authors listed by the most recent posts. It should display the author, its avatar, the date, and the title of the post (with a link).
I have it ...
1
vote
1answer
372 views
Loop through child images of a parent for a Nivo Slider
I want to use a Nivo slider to cycle through the children of a parent page one by one, how can I do that?
I have the following piece of code that grabs ALL the children of a parent page and displays ...
-1
votes
1answer
221 views
Combine two foreach Arrays into one table row
right now I have two foreach arrays - one outputs the artist, the other a track title
I would like to combine both so there is a row for each artist and corresponding track
for example:
Row 1 - ...
0
votes
2answers
228 views
Simple foreach loop help needed in wordpress “the loop”
I need a foreach loop inside "the loop"
This is my current code (index.php) :
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div><a href="<?php the_permalink(); ...
2
votes
1answer
399 views
Advanced Custom Fields - Storing array value for further usage
This might might be more of a PHP question - but does deal with a WordPress plugin, Advanced Custom Fields
I am using a global select option to store a specific Location (custom post type) as the ...
0
votes
1answer
571 views
Display metabox title for custom fields with values
I'm using multiple metabox panels in my write posts. IN my functions I'm registering multiple metaboxes:
$prefix = 'dbt_';
$meta_boxes = array();
$meta_boxes[] = array(
'id' => ...
0
votes
1answer
317 views
Retrieve IDs from custom field, count and display results differently according to count
The function below is inside a single post loop.
I have an array of IDs in a custom field. Such IDs represent related posts. I'm using Advanced Custom Fields (ACV) plugin and I manage the custom ...
0
votes
2answers
238 views
Code that displays images - images get shown multiple times
On My category.php page i've got a list of categories with the title and the description.
Here's the code:
<?php
$cat_id = get_query_var('cat');
$catlist = ...
0
votes
2answers
346 views
Add class to last 3 posts in loop
I have this code so far, which adds the classes first, second, and third to every first, second and third post in the loop. It also adds a class to the first 3 posts in the loop. But how can I make it ...
1
vote
3answers
171 views
query in category.php repeats itself
I'm need some help on my query.
I'm building up a category page where on top a post need to show where custom field key 'uitleg' has value 'ja'. Per category there is only one post with that value. ...
0
votes
3answers
330 views
Custom Database Table and foreach
I have just created a custom database table and would now like to output every inserted row from it into a predefined format using a foreach statement.
Some guidance in this matter would be great.
...
0
votes
1answer
782 views
Count within foreach loop
How can I echo out the count of within a foreach loop? I want to change the class of the div below so it's menu-button-1, menu-button-2 etc etc:
<?php
$pages = get_children(array('orderby' ...
0
votes
1answer
226 views
Shortcode, Concatenating & Parse error: syntax error, unexpected T_FOREACH
I'm learning how to write a shortcode. I'm getting this error: Parse error: syntax error, unexpected T_FOREACH . I'm having problems with concatenating it properly.
<?php
/*
Plugin Name: My ...
1
vote
2answers
268 views
Make Selected Mutiselect Items “selected”
I'm developing a theme settings panel for a new wordpress theme that have an option to exclude categories from being shown in the loop. I managed to get the main functionality to work, using a ...
1
vote
2answers
2k views
In a foreach loop, how do I target the last item in the loop?
I have the following code to do a foreach loop, I want to target the last item in the loop (e.g if it's looped over 3 events I want to target the 3rd event) to do something slightly different with the ...
1
vote
1answer
720 views
Limit get_pages to only show 5 items
How can I limit the get_pages to only show 5 items?
I thought adding 'number' => 5 to the array would limit it to 5 but it doesn't show anything. Here's my code:
<?php
$pages = ...
0
votes
1answer
436 views
Wordpress: paginating array using a foreach
I currently grab an array of user data from a query. I then use a foreach to loop through them and apply styles and divs to output them to the page. This all works great but i would like to paginate ...
1
vote
2answers
1k views
mysql query two database tables, users and usermeta and sort by custom meta int value
I am trying to get an array of site users sorted by a custom meta value (an int).
I can query the users just fine and get them back to use in a foreach. I currently have the query results come back ...
0
votes
2answers
962 views
WordPress MS wp-admin/includes/post.php error with shortcode generator
I'm having a serious issue with Wordpress 3.1 with Multi Site enabled and my themes custom shortcode generator. For some reason, I'm getting the following error whenever I create a new ...
0
votes
2answers
671 views
Using a loop to display terms associated with a post
I'm using a custom post type and custom taxonomies, and using the following to display the terms of the taxonomies on the post page:
the_terms( $post->ID, 'taxname', 'beforetext', ', ');
Is ...