The tag has no wiki summary.

learn more… | top users | synonyms

4
votes
2answers
5k 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 ...
3
votes
2answers
828 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 = ...
3
votes
1answer
274 views

Endless loop with wp_insert_post and wp_update_post

I have an array $unqiues which contains URL's, I loop over the array with the code below to get the URL titles, insert a new post, update the post meta. Then I change the the posts title and name to ...
3
votes
1answer
40 views

foreach error on false boolean from get_terms

I'm grabbing an array of page ids that were created in another function which I use regularly- that's all good. The issue I have is in the below function. Some pages have not been assigned an ...
3
votes
1answer
51 views

Add Incrementing ID to each paragraph in the_content

I need to loop through each paragraph in the_content and add an ID to each paragraph with an incremental value. function incrementparagraphs( $content ) { for ($i = 0; $i <count($content); ...
2
votes
3answers
1k 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 ...
2
votes
2answers
130 views

How can i get the last post from wp multisite?

I have to get the last post from my Multisite network on WordPress. For now I use this code for display the last updated post after a cycle on each blog_id: <?php $blogs = get_last_updated(' ', ...
2
votes
2answers
942 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 ...
2
votes
1answer
108 views

Show list of authors with latest post NOT older than a month

I found two bits of code. One gets me posts NOT older than a month the other bit gets me a list of authors and their custom fields, names, etc. Can someone please help me integrate the two. One runs ...
2
votes
1answer
500 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 ...
2
votes
1answer
88 views

Listing all capabilities in dropdown is returning boolean

Trying to put a list of all possible caps in a dropdown. I can only get it to return 1s (boolean true). If I use var_dump($user->allcaps); it does produce the actual cap names, but when I plug this ...
1
vote
2answers
4k 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
1k 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 ...
1
vote
2answers
501 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
1answer
1k 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 = ...
1
vote
2answers
63 views

Apply different Class for each element in a foreach()

sorry for the silly question, but I am really lost. I want to apply the following CSS to the even elements of my foreach. CSS .blogArticles a { float: left; max-width: 250px; width: 25%; ...
1
vote
3answers
72 views

get_*_meta doesn't always return an array

I find it annoying that functions like get_user_meta or get_post_meta will return an array if the meta key exists or false if it doesn't. This means I need to do a check like so: $meta = ...
1
vote
1answer
258 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 ...
1
vote
1answer
641 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
vote
3answers
262 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. ...
1
vote
2answers
2k 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 ...
1
vote
3answers
82 views

Display the number of published posts for each custom taxonomy term?

I do have a custom taxonomy called "countries". How do I get each term (country) with the number of its published posts in brackets, like the following: Uruguay (3) Chile (5) Thailand (2) etc. ...
1
vote
0answers
228 views

Set default value for radio button in WP Alchemy custom meta box?

I'm using the WP Alchemy Metabox PHP class (www.farinspace.com/wpalchemy-metabox/) to add a custom meta box with a radio select to a custom post type. The code below shows the code I'm using for the ...
1
vote
0answers
19 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
3answers
106 views

How can this crude function be improved?

In the first function below, inside the foreach, I'm calling out to the 2nd function in order to test for the occurence of matching category ids that I want to remove from the category listing. ...
0
votes
1answer
24 views

Why is only the first operation run in my loop - except for on the last repeat? [closed]

We have a custom walker displaying only the sub menu of the current top menu and while making some changes to it I ran into something I don't get - for some reason only the first echo of each loop in ...
0
votes
3answers
104 views

Conditionally set post_content in wp_insert_post

Is it possible to conditionally set the post_content in wp_insert_post? Im using a foreach to add multiple pages at once: foreach ($create_pages as $new_page) { $add_pages = array( ...
0
votes
2answers
68 views

Create menu locations for each category in wordpress

I need display a special menu in each category page in wordpress, for example I have 3 category: horse,dog,cat So I must have 3 menu in Menu Settings locations with name: horse,dog,cat with this ...
0
votes
1answer
405 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 ...
0
votes
2answers
465 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 ...
0
votes
1answer
2k 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
2answers
44 views

Foreach displays from last to first

I created the foreach loop to display post images, but It displays them from last to first, how can I make It to displays from first to last ;) ? <?php $args = array( 'post_type' => ...
0
votes
2answers
70 views

Save checkboxes of a metabox with a foreach loop (invalid argument)

I'm new to Wordpress plugin development and I'm trying to create a list of checkboxes (from a WP Query) to associate as custom fields for a specific post type. Nothing wrong with the display function, ...
0
votes
2answers
208 views

Display post category in foreach loop

I am trying to display post category in a foreach loop. I have all the elements displaying properly except for the category. Here is my function: function my_get_display_author_posts() { global ...
0
votes
2answers
343 views

How to use Wordpress Conditional Tags in get_posts foreach loop

I have a page which has a jquery tab function to output the list of pages that are the children of this page (Bio, Archives, Contact). However I am trying to make a conditional in the foreach loop ...
0
votes
1answer
427 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 ...
0
votes
1answer
478 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
2answers
348 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(); ...
0
votes
1answer
21 views

foreach loop inside the loop creating duplicates in output

I have a foreach loop inside the loop that is getting info from a separate table. The table has a column that has an id that reflects the id of the post type so it should always be unique. When I ...
0
votes
1answer
51 views

Change page template programmatically inside foreach

i have been trying to attach multiple pages, eash to its page-template using a foreach loop... Manually meaning writing each page code works but inside the foreach loop it wont work. I have several ...
0
votes
1answer
109 views

How can i show pagenavi in my author.php?

With this query in author.php i show all posts from a specific author_id/name/slug. But the problem is when i set the minimum of posts to show in the page. I have tried with posts_per_page= but if i ...
0
votes
2answers
113 views

Displaying values from related field - if empty shows current post type's link and title

I'm working with custom post types. In the post type awards I have a relationship field that links each award to a post from the post type project. I'm using the following code to return the values ...
0
votes
1answer
63 views

List all pages including archive

I'm creating a custom options page on my site. One of the options is controlling a box on the homepage and i'm trying to set the link for the item to any page on the site via a select menu. as of now ...
0
votes
1answer
107 views

How to remove certain words from url slug

Trying to create a SEO plugin, that will remove stop words from slugs. This is how to explode the $slug into a list, and explode the variable containing the stop words : add_filter ('sanitize ...
0
votes
1answer
574 views

How to get the next and previous image title from attachment or gallery?

I'm trying to build a slider exactly like this 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 image title for the ...
0
votes
1answer
300 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
1answer
326 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
413 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
95 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
224 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 = ...